In my previous article I explain about some of the major changes in Yii2 Framework. In this article I will guide you to install and setup the configuration web application using Yii2 framework.
One of the new feature in Yii2 is the introduction of Composer.
Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.
We can install Yii2 framework and application using composer. Using composer is very easy and I insist those who havn’t used composer should start using it. Though if you are not intending to use composer you can download Yii2 and install it the same way as in Yii1. I will first explain how to install Yii2 using composer and then the normal download.
Install Yii2 using composer
You need to install Composer inorder to user composer. If you are on Linux or Mac you can install it by executing the following code
curl -s http://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
In Windows you can download the executable installer here. Download and install it. When you install you can choose to add menu item to the right click menu.
With Composer installed, you can install Yii by running the following command under a Web-accessible folder:
composer create-project --prefer-dist yiisoft/yii2-app-basic basic
The above command installs Yii in a directory named
Tip: If you want to install the latest development version of Yii, you may use the following command, which adds a stability option:
12 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.
Installing from an Archive File
Installing Yii from an archive file involves two steps:
- Download the archive file from Yii 2 with basic application template or Yii 2 with advanced application template.
- Unpack the downloaded file to a Web-accessible folder.
- Modify the
config/web.phpfile by entering a secret key for the
cookieValidationKeyconfiguration item (this is done automatically if you are installing Yii using Composer):
12// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation'cookieValidationKey' => 'enter your secret key here',
Verifying the Installation
After installation, you can use your browser to access the installed Yii application with the following URL:
You can check if the minimum requirements are met using one of the following approaches:
- Use a browser to access the URL