Getting started with yii2
Remarks#
Yii is a generic Web programming framework, meaning that it can be used for developing all kinds of Web applications using PHP. Because of its component-based architecture and sophisticated caching support, it is especially suitable for developing large-scale applications such as portals, forums, content management systems (CMS), e-commerce projects, RESTful Web services, and so on.
Versions#
Version | Release Date |
---|---|
2.0.12 | 2017-06-05 |
2.0.11 | 2017-02-01 |
2.0.10 | 2016-10-20 |
2.0.9 | 2016-07-11 |
2.0.8 | 2016-04-28 |
2.0.7 | 2016-02-14 |
2.0.6 | 2015-08-06 |
2.0.5 | 2015-07-11 |
2.0.4 | 2015-05-10 |
2.0.3 | 2015-03-01 |
2.0.2 | 2015-01-11 |
2.0.1 | 2014-12-07 |
2.0.0 | 2014-10-12 |
Installation or Setup
Yii2 can be installed in two ways. They are
- Installing via Composer
- 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
-
Download the archive file from Yii-download
-
Unpack the downloaded file to a Web-accessible folder.
-
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’,
Install Yii2 advanced in ubuntu
First we need to install composer. Steps to install composer Install Composer.
curl -sS https://getcomposer.org/installer | php
Now change directory:
sudo mv composer.phar /usr/local/bin/composer
Check composer working
composer
Now Composer installed.
There two ways to install Yii2 advance.
1.Installing from an Archive File
Get zip file from below link.
Unzip it into destination directory, e.g. /var/www/html
.
https://github.com/yiisoft/yii2/releases/download/2.0.8/yii-advanced-app-2.0.8.tgz
Move inside the “advanced” folder. Move manually or type below command.
cd advanced
Run below command.
php init
2.Installing via Composer
Installing via composer require github authentication token. For token you need to sign up on GitHub.
After signup you can generate your token :
Steps to generate a token
- In the top right corner of any page, click your profile photo, then click Settings.
- In the user settings sidebar, click Personal access tokens.
- Click Generate new token.
- Give your token a descriptive name.
- Select the scopes you wish to grant to this token.
- Click Generate token.
- Copy the token to your clipboard. For security reasons, after you navigate
off this page, no one will be able to see the token again.
Reference : https://help.github.com/articles/creating-an-access-token-for-command-line-use/
After Generating token copy it
Change directory
cd /var/www/html/
Run below command
composer config -g github-oauth.github.com <AuthToken>
example:
composer config -g github-oauth.github.com f1eefb8f188c22dd6467f1883cb2615c194d1ce1
Install yii2
composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced
Move inside the “advanced” folder. Move manually or type below command.
cd advanced
Run below command.
php init
Its done!
Now you can check it.
https://localhost/advanced/frontend/web
and