yii2 Installation or Setup


Yii2 can be installed in two ways. They are

  1. Installing via Composer
  2. Installing from an Archive File

Installing via Composer

Installing Composer

If you do not already have Composer installed, you may do so by following the instructions at getcomposer.org. On Linux and Mac OS X, you'll run the following commands:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

For windows just download and install composer-setup.exe You may have to configure the github API access token to overide Github API rate limit.

Installing Yii

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.2.0"
composer create-project --prefer-dist yiisoft/yii2-app-basic basic

then run the following command to install Yii2 with basic template.

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

To install Yii2 with advanced template run

composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-advanced advanced
cd advanced
php init

After that create a new database and adjust the components['db'] configuration in common/config/main-local.php accordingly. then run the following command to

php yii migrate

Installing from an Archive File

  1. Download the archive file from Yii-download

  2. Unpack the downloaded file to a Web-accessible folder.

  3. Modify the config/web.php file by entering a secret key for the cookieValidationKey configuration item

    You can add any type of key you want:

    'cookieValidationKey' => '',
    For example : xyctuyvibonp
    'cookieValidationKey' => 'xyctuyvibonp',
 //insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'enter your secret key here',