win10系統下php7+nginx的安裝配置
此篇文章針對像作者一樣的小小白閱讀(內容細緻,容易理解,而且有個別問題其他部落格沒有涉及,為了解決小小白們的困惑,分享這篇文章)
一、檔案準備:
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的資訊內容了。