Site icon SmartTutorials.net

Install YII2 Using Composer

In this tutorial we are going to see, how to install YII2 PHP framework using composer. Please follow this tutorial step by step to install YII2 Using Composer successfully.

Composer is package manager for PHP. It will be very easy, if want to upgrade and degrade your Framework if installed via Composer.

  1. Composer Installation for Yii2
  2. Install Yii2 Using Composer

Composer Installation for YII2:

Composer Installation for windows users is very easy. All you need to do is just download .exe installer file from the Composer site.

Here is the .exe installer link to download Composer-Setup.exe

You can also install the Composer using curl using following command.


curl -s https://getcomposer.org/installer | php

Once you successfully installed the Composer, then type composer and press enter in the terminal you will get following response like in the below image.

 

If you had Composer already installed before, make sure you use an up to date version. You can update Composer by running composer self-update


composer self-update

Install YII2 using Composer

Before start to download Yii2 using Composer, You must be in htdocs/www folder to start Yii2 to download. So change the directory in the terminal using cd command .

cd C:\xampp\htdocs

 

Now run the following command using your terminal window.

composer global require "fxp/composer-asset-plugin:~1.1.1"
composer create-project --prefer-dist yiisoft/yii2-app-basic crud

First command installs composer asset plugin which manages the bower and npm packages installation through composer.  Second command installs YII2 in the crud directory. If you installs in different directory then give different name.

While running second command it takes some time to install all the dependable packages from the server. but second time onwards it takes from cache.

 

Once everything installed successfully, then access your YII2 application using following URL.

http://localhost/crud/web

Now also you can check status of your development environment meets the Yii2 framework required status by going through following URL.


http://localhost/crud/requirements.php

Once we meet all the requirement, Then we need to create database and connect via our Yii2 application.

Connect MySQL Database Via Yii2

Create MySQL database using following SQL queries.


CREATE DATABASE `yii2` CHARACTER SET utf8 COLLATE utf8_general_ci;

Now add your MySQL credentials to Yii2 db.php file like this. Find the db.php file in the following folder (C:\xampp\htdocs\crud\config)


<?php
return [
    'class' => 'yii\db\Connection',
    'dsn' => 'mysql:host=localhost;dbname=yii2',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
];


Now we have successfully installed as well as connected to the MySQL database. Next I will post tutorial how develop application using this Yii2 framework.

Exit mobile version