Create a web application using Yii2
The latest version of Yii 2 is 2.0.3, released on March 1, 2015.Related Links
Environment
- OS: Ubuntu 14.04
Installation of an application template
- Find / Create a suitable directory in your hard drive.
- Install Composer
- $ curl -sS https://getcomposer.org/installer | php
- Install the Composer Asset Plugin
- $ php composer.phar global require "fxp/composer-asset-plugin:1.0.0"
- To install the basic application template, run the command below:
- php composer.phar create-project yiisoft/yii2-app-basic basic 2.0.3
- To install the advanced application template, run the command below:
- php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.3
$ curl -sS https://getcomposer.org/installer | php #!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: /Data/nuwan/Research/yii2/app1/composer.phar Use it: php composer.phar $ php composer.phar global require "fxp/composer-asset-plugin:1.0.0" Changed current directory to /home/nuwan/.composer ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) - Removing fxp/composer-asset-plugin (1.0.x-dev dc24e62) - Installing fxp/composer-asset-plugin (v1.0.0) Downloading: 100% Writing lock file Generating autoload files $ php composer.phar create-project yiisoft/yii2-app-basic basic 2.0.3 Installing yiisoft/yii2-app-basic (2.0.3) - Installing yiisoft/yii2-app-basic (2.0.3) Downloading: 100% Created project in basic Loading composer repositories with package information Installing dependencies (including require-dev) Reading bower.json of bower-asset/jquery.inputmask (3.1.51) Could not fetch https://api.github.com/repos/RobinHerbots/jquery.inputmask/contents/bower.json?ref=f29e2b535028bde8e1135deb65cb5ed2e081cf39, enter your GitHub credentials to go over the API rate limit A token will be created and stored in "/home/nuwan/.composer/auth.json", your password will never be stored To revoke access to this token you can visit https://github.com/settings/applications Username: srinuwanperera@gmail.com Password: Token successfully created Reading bower.json of bower-asset/bootstrap (v3.1.1) Reading bower.json of bower-asset/bootstrap (v3.3.1) - Installing yiisoft/yii2-composer (2.0.3) Downloading: 100% - Installing ezyang/htmlpurifier (v4.6.0) Loading from cache - Installing swiftmailer/swiftmailer (v5.4.0) Downloading: 100% - Installing bower-asset/jquery (2.1.3) Downloading: 100% - Installing bower-asset/yii2-pjax (v2.0.4) Downloading: 100% - Installing bower-asset/punycode (v1.3.2) Downloading: 100% - Installing bower-asset/jquery.inputmask (3.1.62) Downloading: 100% - Installing cebe/markdown (1.0.2) Downloading: 100% - Installing yiisoft/yii2 (2.0.3) Downloading: 100% - Installing yiisoft/yii2-swiftmailer (2.0.3) Downloading: 100% - Installing yiisoft/yii2-codeception (2.0.3) Downloading: 100% - Installing bower-asset/bootstrap (v3.3.4) Downloading: 100% - Installing yiisoft/yii2-bootstrap (2.0.3) Downloading: 100% - Installing yiisoft/yii2-debug (2.0.3) Downloading: 100% - Installing bower-asset/typeahead.js (v0.10.5) Downloading: 100% - Installing phpspec/php-diff (v1.0.2) Loading from cache - Installing yiisoft/yii2-gii (2.0.3) Downloading: 100% - Installing fzaninotto/faker (v1.4.0) Downloading: 100% - Installing yiisoft/yii2-faker (2.0.3) Downloading: 100% Writing lock file Generating autoload files chmod('runtime', 0777)...done. chmod('web/assets', 0777)...done. chmod('yii', 0755)...done. $ $ php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.3 Installing yiisoft/yii2-app-advanced (2.0.3) - Installing yiisoft/yii2-app-advanced (2.0.3) Downloading: 100% Created project in advanced Loading composer repositories with package information Installing dependencies (including require-dev) - Installing yiisoft/yii2-composer (2.0.3) Loading from cache - Installing ezyang/htmlpurifier (v4.6.0) Loading from cache - Installing swiftmailer/swiftmailer (v5.4.0) Loading from cache - Installing bower-asset/jquery (2.1.3) Loading from cache - Installing bower-asset/yii2-pjax (v2.0.4) Loading from cache - Installing bower-asset/punycode (v1.3.2) Loading from cache - Installing bower-asset/jquery.inputmask (3.1.62) Loading from cache - Installing cebe/markdown (1.0.2) Loading from cache - Installing yiisoft/yii2 (2.0.3) Loading from cache - Installing yiisoft/yii2-swiftmailer (2.0.3) Loading from cache - Installing yiisoft/yii2-codeception (2.0.3) Loading from cache - Installing bower-asset/bootstrap (v3.3.4) Loading from cache - Installing yiisoft/yii2-bootstrap (2.0.3) Loading from cache - Installing yiisoft/yii2-debug (2.0.3) Loading from cache - Installing bower-asset/typeahead.js (v0.10.5) Loading from cache - Installing phpspec/php-diff (v1.0.2) Loading from cache - Installing yiisoft/yii2-gii (2.0.3) Loading from cache - Installing fzaninotto/faker (v1.4.0) Loading from cache - Installing yiisoft/yii2-faker (2.0.3) Loading from cache Writing lock file Generating autoload files $ $ ll total 1068 drwxrwxr-x 4 nuwan nuwan 4096 මාර් 27 13:03 ./ drwxrwxr-x 3 nuwan nuwan 4096 මාර් 27 12:10 ../ drwxrwxr-x 9 nuwan nuwan 4096 මාර් 27 13:08 advanced/ drwxrwxr-x 13 nuwan nuwan 4096 මාර් 27 12:50 basic/ -rwxr-xr-x 1 nuwan nuwan 1075141 මාර් 27 12:12 composer.phar* $
Initialize the application (For advanced template)
- ./init
$ ./init Yii Application Initialization Tool v1.0 Which environment do you want the application to be initialized in? [0] Development [1] Production Your choice [0-1, or "q" to quit] 0 Initialize the application under 'Development' environment? [yes|no] yes Start initialization ... generate common/config/main-local.php generate common/config/params-local.php generate frontend/web/index-test.php generate frontend/web/index.php generate frontend/config/main-local.php generate frontend/config/params-local.php generate backend/web/index-test.php generate backend/web/index.php generate backend/config/main-local.php generate backend/config/params-local.php generate yii generate console/config/main-local.php generate console/config/params-local.php generate cookie validation key in backend/config/main-local.php generate cookie validation key in frontend/config/main-local.php chmod 0777 backend/runtime chmod 0777 backend/web/assets chmod 0777 frontend/runtime chmod 0777 frontend/web/assets chmod 0755 yii ... initialization completed. $
Test the application using php server.
- Basic Application
- php -S localhost:8000 -t basic/web
- Advanced Application
- php -S localhost:8000 -t advanced/frontend/web/
- php -S localhost:8000 -t advanced/backend/web/
- Once the php server started, open a web browser and visit:
- http://localhost:8000/
$ php -S localhost:8000 -t advanced/frontend/web/ PHP 5.5.9-1ubuntu4.7 Development Server started at Fri Mar 27 13:28:22 2015 Listening on http://localhost:8000 Document root is /*******/advanced/frontend/web Press Ctrl-C to quit.