Install YII2 Using Composer

Posted by & filed under PHP, YII2.

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
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.

Composer Installation

 

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

 

CakePHP 3 installation step by step

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.

YII2 Installation via composer

 

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

http://localhost/crud/web
YII Installation Welcome Page

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.

Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts

If you want any of my script need to be customized according to your business requirement,

Please feel free to contact me [at] muni2explore[at]gmail.com

Note: But it will be charged based on your customization requirement

Get Updates, Scripts & Other Useful Resources to your Email

Join 10,000+ Happy Subscribers on feedburner. Click to Subscribe (We don't send spam)
Every Email Subsciber could have access to download 100+ demo scripts & all future scripts.

Get Instant Script Download Access!