用yii2以來,安裝composer總是不成功,因此一直在windows下的php裏,用直接解壓的方法運行yii2。php
後來愈來愈多的場合,須要用composer,終於下決心,要在Linux下搞掂它!html
-----------------------------------------jquery
1、安裝composer
# curl -sS https://getcomposer.org/installer | php
這個總是下載不成功。乾脆手動下載 composer.pchar,再扔進服務器,而後:
# mv composer.phar /usr/local/bin/composer
# chmod +x user/local/bin/composerweb
因爲composer強烈不建議在root下運行。我創建了一個新用戶
# adduser yii2json
設置國外鏡像(不然會被牆)
$ composer config -g repo.packagist composer https://packagist.phpcomposer.com
而後安裝一個什麼插件?
$ composer global require "fxp/composer-asset-plugin:1.0.0-beta3"
這裏又出錯了。一堆錯誤信息。我去掉後面的版本號
$ composer global require "fxp/composer-asset-plugin"
出現提示:
- Installing fxp/composer-asset-plugin (v1.2.2) ...
這樣就行了。windows
2、安裝yii2
$ composer create-project --prefer-dist yiisoft/yii2-app-basic basic
- yiisoft/yii2 2.0.9 requires bower-asset/jquery 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable -> no matching package found.
看了 http://blog.csdn.net/wsliangjian/article/details/46738739服務器
$ cd basic
$ composer update
一些操做後,(下載了N多文件),提示輸入token,
查到這個 https://getyii.com/topic/default/view/32 解決使用Composer的時候提示輸入Token
生成了 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXyii2
如下下載了一大堆東西。
再次測試生成的web網站,出現:
Failed to create directory "/www/default/basic/runtime/logs": mkdir(): Permission denied
$ chmod g+w -R basic
(此處我將yii2與www設爲同組,因此能夠設置組內可寫)
再進web頁面,出現:
yii\web\Request::cookieValidationKey must be configured with a secret key.
此處,修改 config/web.php,在components下,request下,cookieValidationKey後面,隨機輸入一堆字符,保存。
再試,經過!cookie
===============================================app
一氣呵成,繼續解決了windows7下安裝!
C>composer config -g repo.packagist composer https://packagist.phpcomposer.com
C>composer config -g -- disable-tls true
修改php.ini,去掉 extension=php_openssl.dll 前的 ;
C>composer global require "fxp/composer-asset-plugin"
Changed current directory to C:/Users/Administrator/AppData/Roaming/Composer
You are running Composer with SSL/TLS protection disabled.
Using version ^1.2 for fxp/composer-asset-plugin
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing fxp/composer-asset-plugin (v1.2.2)
Downloading: 100%
Writing lock file
Generating autoload files
C>composer update
C>composer create-project --prefer-dist yiisoft/yii2-app-basic mybasic
OK!!!
----------------------------------------
以上參考了:http://www.cnblogs.com/yangtoude/p/5323561.html composer安裝yii2問題總結http://www.yiichina.com/topic/6423 composer安裝Yii2,寫給老是安裝不成功的朋友!