yii2框架的安装配置启动
top:環(huán)境MacBook
1、通過composer 安裝yii2 【yii2需要php的PDO和pdo_mysql擴(kuò)展,需要確認(rèn)已安裝】
a. 首先需要配置composer:
我使用的是阿里云的鏡像:https://developer.aliyun.com/composer
具體配置參照阿里云的文檔,具體使用全局composer命令百度 or Google
b. 安裝yii2:
yii2china.com上的文檔通過composer安裝yii2的命令是:composer create-project --prefer-dist yiisoft/yii2-app-basic basic
成功的話會(huì)在www目錄建立一個(gè)basic目錄,里面為代碼
安裝時(shí)可能遇到的問題有:
可能會(huì)遇到的問題1:
這個(gè)問題其實(shí)我不確定是否解決了,因?yàn)槲仪耙惶煊龅搅?#xff0c;第二天百度下執(zhí)行了 composer self-update之后,再composer就沒了。
可能會(huì)遇到的問題2:
Your requirements could not be resolved to an installable set of packages.Problem 1- The requested package bower-asset/jquery could not be found in any version, there may be a typo in the package name.Problem 2- The requested package bower-asset/inputmask could not be found in any version, there may be a typo in the package name.Problem 3- The requested package bower-asset/punycode could not be found in any version, there may be a typo in the package name.Problem 4- The requested package bower-asset/yii2-pjax could not be found in any version, there may be a typo in the package name.Potential causes:- A typo in the package name- The package is not available in a stable-enough version according to your minimum-stability settingsee <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.- It's a private package and you forgot to add a custom repository to find itRead <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.問題2解析:Yii依靠 Bower 和/或 NPM 軟件包來安裝 asset(CSS 和 JavaScript)庫。 它使用Composer來獲取這些庫,允許 PHP 和 CSS/JavaScript 包版本同時(shí)解析。
問題2是我第一次create-project的時(shí)候,執(zhí)行了這個(gè)錯(cuò)誤的命令:composer create-project --prefer-dist yiisoft/yii2 ,遇到的。
解決方式為:composer安裝composer bower-asset的幾個(gè)包
可能會(huì)遇到的問題3:
安裝的時(shí)候如果提示需要提供Token(hidden):? 這里是需要你提供github的token
獲取token方式為:
登錄github->點(diǎn)擊頭像->Settings->左欄最下Developer settings->左欄Personal access tokens->Generate new token
然后創(chuàng)建一個(gè)tab,選項(xiàng)全勾選,生成token,之后拿這個(gè)token復(fù)制到Token(hidden): 那里即可繼續(xù)安裝。
之后即可安裝成功,框架入口文件為web/index.php。
2、配置啟動(dòng)
a. 使用yii2提供的命令行啟動(dòng)測試服務(wù)器:
yii2提供了yii2 serve 可以本地啟動(dòng)服務(wù)作為測試使用
命令為:php72 yii serve --docroot='/data0/www/basic/web' --port=8888
瀏覽器訪問http://localhost:8888/ 即可看到恭喜頁面。
說一下--docroot這個(gè)參數(shù)項(xiàng):該參數(shù)為指定web根目錄
起初按照文檔執(zhí)行 php yii serve --port=8888時(shí),報(bào)錯(cuò)為:Document root "/data0/www/yii2/console/web" does not exist.
百度加google之后,報(bào)錯(cuò)原因?yàn)?#xff1a;
直接執(zhí)行 php yii serve,不指定docroot時(shí),yii2無法知道你的項(xiàng)目根目錄要的是哪個(gè)目錄,是前臺目錄,還是后臺目錄?所以得手動(dòng)指定下web目錄。
b. nginx配置項(xiàng)目:
根據(jù)官網(wǎng)的nginx配置文件走即可:
另外官網(wǎng)的nginx服務(wù)建議項(xiàng)還有:
使用該配置時(shí),你還應(yīng)該在 php.ini 文件中設(shè)置 cgi.fix_pathinfo=0 , 能避免掉很多不必要的 stat() 系統(tǒng)調(diào)用。
還要注意當(dāng)運(yùn)行一個(gè) HTTPS 服務(wù)器時(shí),需要添加 fastcgi_param HTTPS on; 一行, 這樣 Yii 才能正確地判斷連接是否安全。
?
轉(zhuǎn)載于:https://www.cnblogs.com/deverz/p/11389520.html
總結(jié)
以上是生活随笔為你收集整理的yii2框架的安装配置启动的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑插上优盘找不到怎么回事 电脑无法识别
- 下一篇: win10摄像头卸载了怎么回事 Win1