Installing Yii2.0

We can install Yii in two ways, using Composer or downloading an archive file. The former is the preferred way as it allows you to install new extensions or update Yii by running a single command.

Install Composer

  • Download the composer from
  • When you install the composer, It will ask to choose the “php.exe” file.
  • on Linux or Mac, run the following commands:
    curl -s | php mv composer.phar /usr/local/bin/composer
  • To check the composer installation, Type the below code in command prompt
    composer -V
  • With Composer installed, you can install Yii by running the following commands under a Web-accessible folder:
    composer global require "fxp/composer-asset-plugin:1.0.0-beta2"

    The first command installs the composer asset plugin which allows managing bower and npm package dependencies through Composer. You only need to run this command once for all.

Installing Yii Via Composer

Yii2 are having two apppliation in They are “Advanced application template”, “Basic application template”

Install Advanced Application Template

Install yii2 application via composer

To install “advanced application template”, use the following code

composer create-project yiisoft/yii2-app-advanced projAdvanced 2.0.0-beta


php composer.phar create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced/path/to/yii-application


composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-advancedyour_project_name


Install Basic Application Template

To install “basic application template”, use the following code

composer create-project yiisoft/yii2-app-basic projBasic 2.0.0-beta


composer create-project --prefer-dist yiisoft/yii2-app-basic basic_project_name


composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic basic_project_name
Folder Structure Of Advanced Application Template

After installed ‘advanced application template’, you will get the application like below folder structure.

yii2 advanced application folder structure

Root directory contains a set of folder.

  • backend – backend web application.
  • common – files common to all applications.
  • console – console application.
  • environments – environment configs.
  • frontend – frontend web application.

Root directory contains a set of files.

  • .gitignore contains a list of directories ignored by git version system. If you need something never get to your source code repository, add it there.
  • composer.json – Composer config described in detail below.
  • init – initialization script described in “Composer config described in detail below”.
  • init.bat – same for Windows.
  • – license info. Put your project license there. Especially when opensourcing.
  • – basic info about installing template. Consider replacing it with information about your project and its installation.
  • requirements.php – Yii requirements checker.
  • yii – console application bootstrap.
  • yii.bat – same for Windows.

Installing from an Archive File

Installing Yii from an archive file involves two steps:

  1. Download the archive file from
  2. Unpack the downloaded file to a Web accessible folder.

Getting Started

After you install the application, you have to conduct the following steps to initialize the installed application. You only need to do these once for all. Yii2 Installation Via Composer

  1. Run command init to initialize the application with a specific environment.
  2. Create a new database and adjust the components[‘db’] configuration in common/config/main-local.php accordingly.
  3. Apply migrations with console command yii migrate. This will create tables needed for the application to work.
  4. Set document roots of your Web server:


Leave a Reply

Your email address will not be published. Required fields are marked *