vagrant的學習 之 Yii2

vagrant的學習 之 Yii2


 本文根據慕課網的視頻教程練習,感謝慕課網!php

慕課視頻學習地址:https://www.imooc.com/video/14218html

慕課的參考文檔地址:https://github.com/apanly/mooc/tree/master/va nginx

Yii2的中文官網地址:https://www.yiichina.com/git


 

第一步,須要安裝composer:

curl -sS https://getcomposer.org/installer | php

返回失敗:github

All settings correct for using Composer
Downloading...
Failed to decode zlib stream

再次執行該命令,返回成功:web

All settings correct for using Composer
Downloading...

Composer (version 1.7.2) successfully installed to: /home/www/yii2/composer.phar
Use it: php composer.phar

而後把composer修改成全局變量,執行:apache

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

第二步,安裝Yii:

composer create-project --prefer-dist yiisoft/yii2-app-basic basic

報錯:json

Cannot create cache directory /home/vagrant/.composer/cache/repo/https---repo.packagist.org/, 
or directory is not writable. Proceeding without cache

給目錄增長權限:vim

sudo chmod -R 777 /home/vagrant/.composer/cache/

再次執行,仍是報錯:yii2

The "https://repo.packagist.org/packages.json" file could not be downloaded: SSL: crypto enabling timeout
Failed to enable crypto
failed to open stream: operation failed
https://repo.packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

                                                                  [Composer\Downloader\TransportException]                                   
  Content-Length mismatch, received 19839 bytes out of the expected 1080215 

超時了,搜索後嘗試修改composer的國內鏡像下載地址,實現加速試一試:

composer config -g repo.packagist composer https://packagist.phpcomposer.com

結果顯示無權限:

[ErrorException]                                                                              
  touch(): Unable to create file /home/vagrant/.composer/config.json because Permission denied

給文件增長權限:

sudo chmod -R 777 /home/vagrant/.composer/

而後再次執行修改composer的下載地址:

  composer config -g repo.packagist composer https://packagist.phpcomposer.com

此次沒有報錯,查看配置文件已經修改:

cat /home/vagrant/.composer/config.json

顯示:

{
    "config": {},
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "https://packagist.phpcomposer.com"
        }
    }
}

而後再次嘗試下載yii框架:

composer create-project --prefer-dist yiisoft/yii2-app-basic basic

下載成功,發現目錄下多了個basic目錄

重命名項目名字:

mv basic yii2

第三步,配置nginx:

//進入nginx的配置目錄
cd /etc/nginx/conf.d/
//常見yii的配置文件
sudo touch yii2.conf
//編輯配置文件
sudo vim yii2.conf
//文件內容
server{
        server_name study.yii2.com;
        root /home/www/yii2/web;
        index index.php index.html;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }


        location ~ \.php${
                include fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                try_files $uri = 404;

        }
}

修改host文件:

sudo vim  /etc/hosts

增長:

IP地址   study.yii2.com

而後重啓nginx

sudo /etc/init.d/nginx restart

最後配置本地主機的host文件:

也增長:

IP地址  study.yii2.com

就能夠在本地訪問 study.yii2.com 了。


 

第四步,配置apache:

 進入apache的配置目錄:

cd /etc/apache2/sites-enabled

建立配置文件:

sudo touch yii2.conf

編輯配置文件:

sudo vim yii2.conf
<VirtualHost *:8888>
        ServerName study.yii2.com
        DocumentRoot /home/www/yii2/web/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

重啓apache:

sudo /etc/init.d/apache2 restart

ok,配置完成。


 

總結:

  一、雖然看視頻或者文檔感受簡單,很快就看完了,可是本身並無記住,仍是須要多加練習才行;

  二、實際操做起來更會有不少意外的錯誤發生,這時候就須要耐心,分析解決問題,有的錯誤可能很快找到解決方法,可是有些卻耗費時間也沒有搜到答案,只能另尋途徑或暫時跳過。

  


 

歡迎你們指點。

相關文章
相關標籤/搜索