本文參考了http://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.html和
https://blog.csdn.net/gfj0814/article/details/76400778
此篇文章針對像作者一樣的小小白閱讀(内容細緻,容易了解,而且有個别問題其他部落格沒有涉及,為了解決小小白們的困惑,分享這篇文章)
一、檔案準備:
php7:VC14 x64 Non Thread Safe (2018-Oct-10 19:11:21)(下載下傳PHP 7.1 (7.1.23)中的zip檔案)
nginnx:nginx/Windows-1.14.0(下載下傳stable version)
RunHiddenconsole:(作用:可以代替指令行的操作)
連結:https://pan.baidu.com/s/15phuQTyDCF1i11pwucNIJA
提取碼:kyam
二、安裝與配置
1.php的安裝與配置
建立wnmp檔案,将下載下傳好的php封包件解壓到該目錄下,例如我的是:D:\users\lh\wnmp。把解壓後的檔案目錄改為php7,将裡面的php.ini-development檔案複制一份并改名為php.ini,用文本編輯器将它打開。(不要用記事本,記事本打開内容格式混亂,而且沒有查找功能,建議使用Notepad++或者是寫字闆)
标題
在寫字闆中查找搜尋on windows
找到
; On windows:
;extension_dir = ".\ext"
改為(将extension_dir前面的;去掉)
; On windows:
extension_dir = "D:\users\lh\wnmp\php7\ext"
繼續查找搜尋extension找到
;extension=php_mysqli.dll
;extension=php_pdo_mysql.dll
将這兩行代碼前面的;去掉
繼續查找搜尋cgi.fix_pathinfo
找到
;cgi.fix_pathinfo=1
将前面的;去掉
2.nginx的安裝與配置
在D:\users\lh\wnmp下建立www檔案,作為伺服器的根目錄
将下載下傳好的nginx壓縮檔案解壓到wnmp目錄下,重命名nginx,打開nginx\conf下的nginx.conf檔案來配置nginx
将
location/ {
root html;
index index.html index.htm;
}
改為
location/ {
root D:\users\lh\wnmp\www; #将站點的根目錄定位到D:\users\lh\wnmp\www
index index.html index.htm;
}
将
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
改為
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root D:\users\lh\wnmp\www;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
# 這裡$document_root指的是上面定義好的nginx根目錄:D:\users\lh\wnmp\www
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
ctrl+s儲存配置即可
三、啟動
1.手動啟動
1)指令行php目錄下鍵入 php-cgi.exe -b 127.0.0.1:9000 -c D:\users\lh\wnmp\php7/php.ini(輸入以後光标閃爍,但是不能沒有其他反應,但是關掉指令行)
圖示:
2)重新打開cmd,指令行nginx目錄下 start nginx
3)在www目錄下建立一個phpinfo.php檔案
<?php
phpinfo();
?>
4)浏覽器中輸入localhost/phpinfo.php,出現以下内容代表運作成功
2.非手動啟動(哈哈)
用記事本寫兩個腳本,分别為start_nginx.bat和stop_nginx.bat,将它們都放在nginx目錄下。完成後輕按兩下這兩個腳本就可以啟動和關閉nginx了。
start_ngin.bat内容如下
@echo off
REM Windows 下無效
REM set PHP_FCGI_CHILDREN=5
REM 每個程序處理的最大請求數,或設定為 Windows 環境變量
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
RunHiddenConsole D:\users\lh\wnmp\php7/php-cgi.exe -b 127.0.0.1:9000 -c D:\users\lh\wnmp\php7/php.ini
echo Starting nginx...
RunHiddenConsole C:/wnmp/nginx/nginx.exe -p D:\users\lh\wnmp\nginx
注意:根據自己的情況修改腳本中出現的路徑
stop_ngin.bat内容入下
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
檔案放置如下
下回直接點選start_ngin.bat,再在浏覽器輸入localhost/phpinfo.php就能出現php的資訊内容了。