yii2 advance安裝

轉載自:http://www.genshuixue.com/i-cxy/p/7986531php

1. 前提條件,php版本得> 5.4

D:\phpStudy>php -v PHP 5.5.17 (cli) (built: Sep 16 2014 16:17:50) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies D:\phpStudy>

2. 安裝方式,一種是直接下載壓縮包,推薦採用composer方式安裝,將來的趨勢。安裝直接確保php已經支持openssl (php.ini)查找Openssl
2.1 下載安裝composer , 個人環境是windows的 。

http://getcomposer.org/doc/00-intro.md#installation-nix

附:linux安裝方式

[root@mty01 2016-06-03]# curl -sS https://getcomposer.org/installer | php Downloading 1.1.2... Composer successfully installed to: /home/haozi/2016-06-03/composer.phar Use it: php composer.phar Some settings on your machine may cause stability issues with Composer. If you encounter issues, try to change the following: Your PHP (5.3.3) is quite old, upgrading to PHP 5.3.4 or higher is recommended. Composer works with 5.3.2+ for most people, but there might be edge case issues. The OpenSSL library (1.0.0-fips) used by PHP does not support TLSv1.2 or TLSv1.1. If possible you should upgrade OpenSSL to version 1.0.1 or above. [root@mty01 2016-06-03]# ls composer.phar [root@mty01 2016-06-03]# du -sh composer.phar 1.6M composer.phar

3. 完成composer安裝以後,須要安裝composer的插件

D:\phpStudy\WWW\yii2>php composer.phar global require "fxp/composer-asset-plugin:~1.1.1" Changed current directory to C:/Users/liuhao14/AppData/Roaming/Composer ./composer.json has been created Loading composer repositories with package information Updating dependencies (including require-dev) - Installing fxp/composer-asset-plugin (v1.1.4) Downloading: 100% Writing lock file Generating autoload files D:\phpStudy\WWW\yii2>

4. 開始安裝以前,須要配置一個 github的token,這裏不作敘述。意思是須要申請一個github的帳號,而後生成一個token。
 參照以下路徑,設置(注意下面xxxx明顯是打碼了,因此你直接使用用不了)

C:\Users\liuhao14\AppData\Roaming\Composer>dir /b .htaccess auth.json composer.json composer.lock composer.phar vendor C:\Users\liuhao14\AppData\Roaming\Composer>type auth.json { "github-oauth": { "github.com": "xxxxxxxxxxx6fc824ea5a76ebc5fcdxxxxxxxxxx" } } C:\Users\liuhao14\AppData\Roaming\Composer>

5.重頭戲,開始安裝。因爲國內環境的問題,安裝時間比較長,半個小時也常見,只要程序沒死,不要切斷.....

D:\phpStudy\WWW\yii2>php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.8 Installing yiisoft/yii2-app-advanced (2.0.8) - Installing yiisoft/yii2-app-advanced (2.0.8) Loading from cache Created project in advanced Loading composer repositories with package information Updating dependencies (including require-dev) - Installing yiisoft/yii2-composer (2.0.4) Downloading: 100% - Installing swiftmailer/swiftmailer (v5.4.2) Downloading: 100% - Installing bower-asset/jquery (2.2.4) Downloading: 100% - Installing bower-asset/yii2-pjax (v2.0.6) Downloading: 100% - Installing bower-asset/punycode (v1.3.2) Downloading: 100% - Installing bower-asset/jquery.inputmask (3.2.7) Downloading: 100% - Installing cebe/markdown (1.1.0) Downloading: 100% - Installing ezyang/htmlpurifier (v4.7.0) Downloading: 100% - Installing yiisoft/yii2 (2.0.8) Downloading: 100% - Installing yiisoft/yii2-swiftmailer (2.0.5) Downloading: 100% - Installing yiisoft/yii2-codeception (2.0.5) Downloading: 100% - Installing bower-asset/bootstrap (v3.3.5) Downloading: 100% - Installing yiisoft/yii2-bootstrap (2.0.6) Downloading: 100% - Installing yiisoft/yii2-debug (2.0.6) Downloading: 100% - Installing bower-asset/typeahead.js (v0.11.1) Downloading: 100% - Installing phpspec/php-diff (v1.1.0) Downloading: 100% - Installing yiisoft/yii2-gii (2.0.5) Downloading: 100% - Installing fzaninotto/faker (v1.6.0) Downloading: 100% - Installing yiisoft/yii2-faker (2.0.3) Downloading: 100% Writing lock file Generating autoload files D:\phpStudy\WWW\yii2>

5.1 安裝以後須要進行相關配置,初始化

D:\phpStudy\WWW\yii2\advanced>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 backend/config/main-local.php generate backend/config/params-local.php generate backend/web/index-test.php generate backend/web/index.php generate common/config/main-local.php generate common/config/params-local.php generate console/config/main-local.php generate console/config/params-local.php generate frontend/config/main-local.php generate frontend/config/params-local.php generate frontend/web/index-test.php generate frontend/web/index.php generate tests/codeception/config/config-local.php generate yii 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 chmod 0755 tests/codeception/bin/yii ... initialization completed. D:\phpStudy\WWW\yii2\advanced>

5.2 完成數據庫的相關配置,我選擇的是mysql。本身建立相關數據庫,而後配置。打開yii2目錄下的common\config\main-local.php文件,輸入用戶名,密碼,數據庫名字(沒有數據庫名,必須先建立數據庫名字)
5.3 接下來使用yii migrate建立自帶的數據庫

D:\phpStudy\WWW\yii2\advanced>yii migrate Yii Migration Tool (based on Yii v2.0.8) Total 1 new migration to be applied: m130524_201442_init Apply the above migration? (yes|no) [no]:yes *** applying m130524_201442_init > create table {{%user}} ... done (time: 0.308s) *** applied m130524_201442_init (time: 0.496s) 1 migration was applied. Migrated up successfully. D:\phpStudy\WWW\yii2\advanced>

5.3.1 登錄數據庫,驗證一下。應該有2張表(migration / user)【幻風寒影 2016-07-11 14:29:50】

mysql> use yii2advanced Database changed mysql> show tables; +------------------------+ | Tables_in_yii2advanced | +------------------------+ | migration | | user | +------------------------+ 2 rows in set (0.00 sec) mysql>

mysql> desc user; +----------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | username | varchar(255) | NO | UNI | NULL | | | auth_key | varchar(32) | NO | | NULL | | | password_hash | varchar(255) | NO | | NULL | | | password_reset_token | varchar(255) | YES | UNI | NULL | | | email | varchar(255) | NO | UNI | NULL | | | status | smallint(6) | NO | | 10 | | | created_at | int(11) | NO | | NULL | | | updated_at | int(11) | NO | | NULL | | +----------------------+--------------+------+-----+---------+----------------+ 9 rows in set (0.00 sec) mysql> desc migration -> ; +------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+-------+ | version | varchar(180) | NO | PRI | NULL | | | apply_time | int(11) | YES | | NULL | | +------------+--------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql>

6. 如今能夠開始訪問了。

http://localhost/advanced/frontend/web/html

相關文章
相關標籤/搜索