Linux使用Composer安裝yii2的方法及bug處理s()

這裏只講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可以訪問的站點目錄

然後執行命令(注意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 (這裏填寫你在官網註冊的賬戶名)
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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章