yii2的安裝

由於興趣,一直想本身作一個項目,能夠本身修改,升級,就像是呵護本身的產品同樣,萬事開頭難,籌備了好久,進度及其緩慢,由於項目一開始是打算使用yii框架的,因而今天着手準備安裝yii2,雖然遇到了一些狀況,但最終仍是完成了,說一下遇到的情況吧,以防後面會再次遇到,由於這個狀況我不是第一個遇到的,百度了一下,有遇到和我同樣狀況的開發者,將它的分享貼出:php

原文地址【http://www.tuicool.com/articles/iauq2qN】css

這裏只講 linux下安裝Yii2的方法 , windows安裝yii2 的方法 請參見個人另外一篇博文 http://blog.csdn.net/zqtsx/article/details/39344913html

 

第一步 安裝Composer:

語法:「curl -sS https://getcomposer.org/installer | php中bin目錄裏的php可執行文件路徑」node

我這裏的php可執行文件所在路徑是/usr/local/php/bin/phpjquery

因此實際安裝命令以下:linux

curl -sS https://getcomposer.org/installer | /usr/local/php/bin/phpnginx

爲方便往後使用將其移動到本地系統可執行文件目錄 並從新命名爲 composer(這樣之後執行命令時就不用寫composer.phar那麼長的名字,直接寫composer就能夠了)git

mv composer.phar /usr/local/bin/composergithub

第二步 安裝Composer Asset Plugin:web

在命令行執行以下命令注意語法中實際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能夠訪問的站點目錄

而後執行命令(注意php可執行文件路徑和 composer路徑修改爲你本身的安裝路徑):

以下命令將Yii2.0.0版本安裝在名爲 yii2 的目錄中,具體目錄名能夠根據本身的須要修改:

/usr/local/php/bin/php /usr/local/bin/composer create-project yiisoft/yii2-app-basic yii2 2.0.0

須要耐心等待,安裝過程當中可能會出現以下信息要求你輸入用戶名 和密碼(本身到YII官網"https://github.com/"註冊一個帳戶,把帳戶密碼填進去就OK了):

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 (這裏填寫你在官網註冊的帳戶名)

 

輸入帳戶密碼後會出現以下認證成功的提示( 若是沒有就證實你的帳戶密碼錯了,或者你剛在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 

相關文章
相關標籤/搜索