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.
- Download the composer from getcomposer.org
- When you install the composer, It will ask to choose the “php.exe” file.
- on Linux or Mac, run the following commands:
curl -s http://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer
- To check the composer installation, Type the below code in command prompt
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 github.com/yiisoft/yii2. They are “Advanced application template”, “Basic application template”
Install Advanced Application Template
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-advanced your_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.
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.
.gitignorecontains 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.md– license info. Put your project license there. Especially when opensourcing.
README.md– basic info about installing template. Consider replacing it with information about your project and its
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:
- Download the archive file from yiiframework.com
- Unpack the downloaded file to a Web accessible folder.
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.
- Run command init to initialize the application with a specific environment.
- Create a new database and adjust the components[‘db’] configuration in common/config/main-local.php accordingly.
- Apply migrations with console command yii migrate. This will create tables needed for the application to work.
Set document roots of your Web server: