There are two ways for YII Installation,

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

The former is the favoured way, as it lets you install new extensions or update Yii by merely executing a single command.

Standard installations of Yii outcomes both, the framework & a project template being downloaded & installed. A project template is an operational Yii project implementing some simple features, like login, contact form, etc. Its code is structured in a suggested way. Consequently, it can assist as a good beginning point for your projects.

In this & the next section, we will explain how to Install YII with the so-called Basic Project Template & how to implement new features on top of this template. Yii also offers additional template called as the Advanced Project Template which is well utilized in a team development environment to develop applications with multiple tiers.

Note: The Basic Project Template is appropriate for developing 90% of Web applications. It varies from the Advanced Project Template mostly in how their code is organized. If you are new to Yii, we seriously recommend you stick to the Basic Project Template for its simple yet satisfactory functionalities.

YII Installation by Composer

By now, if you do not have Composer installed, you may do so by following the instructions at getcomposer.org. On Mac OS X and Linux, run the below written commands:

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

mv composer.phar /usr/local/bin/composer

For Windows, download & run Composer-Setup.exe.

Please refer to the Composer Documentation if you come across any problems or want to learn more about Composer usage.

If you had already installed Composer earlier, take care you use latest version. You can update Composer by running composer self-update.

After Composer is installed, you can Install YII by running the below commands under a Web-accessible folder:

composer global require “fxp/composer-asset-plugin:~1.1.1”

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

The 1st command installs the composer asset plugin which lets managing bower & npm package dependencies through Composer. You need to run this command only once for all. The 2nd command installs Yii in a directory named basic. You can select another directory name if you need.

Note: Throughout the installation Composer may request for your Github login credentials. This is common as Composer wants to get enough API rate-limit to repossess the dependent package information from Github.

Tip: If you want to install the latest development version of Yii, you may use the following command instead, which adds a stability option:

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

Note that the development version of Yii should not be used for production as it may break your running code.

YII Installation from an Archive File

Installing Yii from an archive file involves three steps:

  1. Download the archive file from yiiframework.com.
  2. Unload the downloaded file to a Web-accessible folder.
  3. Alter the config/web.php file with a secret key for the cookieValidationKey configuration item (this is done automatically if you are installing Yii using Composer):

// !!! insert a secret key in the following (if it is empty) – this is required by cookie validation ‘cookieValidationKey’ => ‘enter your secret key here’,

Leave a Comment