Linux使用Composer安裝yii2的方法及bug處理
這裡只講linux下安裝Yii2的方法,windows安裝yii2 的方法 請參見我的另一篇博文 http://blog.csdn.net/zqtsx/article/details/39344913
第一步 安裝Composer:
語法:“curl -sS https://getcomposer.org/installer | php中bin目錄裡的php可執行檔案路徑”我這裡的php可執行檔案所在路徑是/usr/local/php/bin/php
所以實際安裝命令如下:
curl -sS https://getcomposer.org/installer | /usr/local/php/bin/php
為方便日後使用將其移動到本地系統可執行檔案目錄 並重新命名為 composer(這樣以後執行命令時就不用寫composer.phar那麼長的名字,直接寫composer就可以了)
mv composer.phar /usr/local/bin/composer
第二步 安裝Composer Asset Plugin:
在命令列執行如下命令注意語法中實際php檔案地址和實際composer地址修改成你自己的安裝地址:
(語法:php/bin/php檔案所在路徑 + composer檔案安裝路徑 + global require "fxp/composer-asset-plugin:1.0.0-beta3" 注意空格和標點不要是中文的 )/usr/local/php/bin/php /usr/local/bin/composer global require "fxp/composer-asset-plugin:1.0.0-beta3"
出現類似如下提示資訊說明一切安裝正常(摘取天上星linux下安裝yii2):
“Changed current directory to /root/.composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing fxp/composer-asset-plugin (v1.0.0-beta3)
Downloading: 100%
Writing lock file
Generating autoload files”
第三步 安裝YII2
命令列下切換到一個php可以訪問的站點目錄
Installing yiisoft/yii2-app-basic (2.0.0)
- Installing yiisoft/yii2-app-basic (2.0.0)
Downloading: 100%
Created project in yii2
Loading composer repositories with package information
Installing dependencies (including require-dev)
Reading bower.json of bower-asset/jquery.inputmask (3.1.29)
Could not fetch https://api.github.com/repos/RobinHerbots/jquery.inputmask/contents/bower.json?ref=faf19625822fbd54765d26baac3154cd132769d1, enter your GitHub credentials to go over the API rate limit
The credentials will be swapped for an OAuth token stored in /root/.composer/auth.json, your password will not be stored
To revoke access to this token you can visit https://github.com/settings/applications
Username:myyiiname (這裡填寫你在官網註冊的賬戶名)
Password:myyiipwd (密碼,你懂得)
輸入賬戶密碼後會出現如下認證成功的提示(如果沒有就證明你的賬戶密碼錯了,或者你剛在YII官網註冊的新賬戶沒有通過郵件啟用):
Token successfully created
認證通過的提示資訊下面緊跟著一句如下的進度提示資訊,說明正在安裝過程中,需要你耐心等待,後面的小數點會隨著安裝進度有微妙的變化,
Reading bower.json of bower-asset/typeahead.js (v0.10.0)
然後緊接著緩緩有序的出現一些列如下的進度條,還需要耐心等待(摘取天上星linux下安裝yii2):
- Installing yiisoft/yii2-composer (2.0.0)
Downloading: 100%
- Installing swiftmailer/swiftmailer (v5.3.0)
Downloading: 100%
- Installing bower-asset/jquery (2.1.1)
Downloading: 100%
- Installing bower-asset/yii2-pjax (v2.0.1)
Downloading: 100%
- Installing bower-asset/punycode (v1.3.2)
Downloading: 100%
- Installing bower-asset/jquery.inputmask (3.1.41)
Downloading: 100%
- Installing cebe/markdown (1.0.1)
Downloading: 100%
- Installing ezyang/htmlpurifier (v4.6.0)
Downloading: 100%
- Installing yiisoft/yii2 (2.0.0)
Downloading: 100%
- Installing yiisoft/yii2-swiftmailer (2.0.0)
Downloading: 100%
- Installing yiisoft/yii2-codeception (2.0.0)
Downloading: 100%
- Installing bower-asset/bootstrap (v3.2.0)
Downloading: 65%
直到出現類似如下完整資訊,說明YII2下載安裝結束
Installing yiisoft/yii2-app-basic (2.0.0)
- Installing yiisoft/yii2-app-basic (2.0.0)
Loading from cache
Created project in yii2
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing yiisoft/yii2-composer (2.0.0)
Loading from cache
- Installing swiftmailer/swiftmailer (v5.3.0)
Loading from cache
- Installing bower-asset/jquery (2.1.1)
Loading from cache
- Installing bower-asset/yii2-pjax (v2.0.1)
Loading from cache
- Installing bower-asset/punycode (v1.3.2)
Loading from cache
- Installing bower-asset/jquery.inputmask (3.1.41)
Loading from cache
- Installing cebe/markdown (1.0.1)
Loading from cache
- Installing ezyang/htmlpurifier (v4.6.0)
Loading from cache
- Installing yiisoft/yii2 (2.0.0)
Loading from cache
- Installing yiisoft/yii2-swiftmailer (2.0.0)
Loading from cache
- Installing yiisoft/yii2-codeception (2.0.0)
Loading from cache
- Installing bower-asset/bootstrap (v3.2.0)
Downloading: 100%
- Installing yiisoft/yii2-bootstrap (2.0.0)
Downloading: 100%
- Installing yiisoft/yii2-debug (2.0.0)
Downloading: 100%
- Installing bower-asset/typeahead.js (v0.10.5)
Downloading: 100%
- Installing phpspec/php-diff (v1.0.2)
Downloading: 100%
- Installing yiisoft/yii2-gii (2.0.0)
Downloading: 100%
- Installing fzaninotto/faker (v1.4.0)
Downloading: 100%
- Installing yiisoft/yii2-faker (2.0.0)
Downloading: 100%
Writing lock file
Generating autoload files
chmod('runtime', 0777)...done.
chmod('web/assets', 0777)...done.
chmod('yii', 0755)...done.
到這裡整個YII2就安裝結束了
第四步 測試yii2是否安裝成功
首先修改nginx 或apache 配置資訊,將yii2目錄新增為虛擬站點目錄
我這裡是nginx配置的,直接在nginx 裡新增一個yii2的站點 目錄就成了在nginx裡新增類似如下站點設定即可,我們這裡的yii2安裝目錄是 /var/www/yii2 所以 設定站點目錄為/var/www/yii2
因為之前127.0.0.1 和127.0.0.2 已經有兩個專案在了,所以這裡就設定yii2站點本地 ip為 127.0.0.3
我的具體配置如下:
server {
listen 80;
listen 127.0.0.3;
server_name somename alias another.alias;
location / {
root /var/www/yii2/;
index index.php index.html index.htm;
}
location ~ \.php$ {
#root html;
root /var/www/yii2/;
#an quan guo lv
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#include fastcgi_params;
include fastcgi.conf;
}
location ~* \.(?:gif|ico|jpe?g|png|swf|bmp|mp3)$ {
valid_referers none blocked 127.0.0.3 localhost baidu.com *.baidu.com google.com.hk *.google.com.hk *.google.com;
if ( $invalid_referer ) {
return 404;
}
#
#expires 30d;
log_not_found off;
## No need to bleed constant updates. Send the all shebang in one
#
# fell swoop.
#
tcp_nodelay off;
#
# Set the OS file cache.
#
open_file_cache max=1000 inactive=120s;
open_file_cache_valid 125s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
root /var/www/yii2/;
#
}
location ~* \.(js|css|mid)$ {
expires 1d;
root /var/www/yii2/;
}
}
然後在瀏覽器中輸入http://127.0.0.3/web/ 即可看到 yii2站點的主頁資訊
至此,說明yii2.0.0版本安裝、測試一切OK,可以開始您的開發之旅了……
第五步 yii2出現Calling unknown method: yii\web\UrlManager::addRules()錯誤的解決方案:
安裝後訪問yii時如果遇到類似Calling unknown method: yii\web\UrlManager::addRules() 的錯誤,請參見摘取天上星的另一篇博文:
http://blog.csdn.net/zqtsx/article/details/39345015