一、下載相關軟體
nginx下載:http://nginx.org/en/download.html
nginx常見異常:http://feiger.cn/?p=2719
php下載:http://windows.php.net/download#php-7.0
下載RunHiddenConsole:http://www.xdowns.com/soft/1/71/2012/Soft_89261.html
二、配置
nginx.conf檔案,我的編輯結果如下所示,具體配置過程中需要注意什麼請看注釋:
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root D:\work\soft\php\www;#網站目錄
index index.html index.php;#加上對php的支援
autoindex on;#如果檔案不存在列出目錄結構;
}
location ~ \.php$ {
root D:\work\soft\php\www;
fastcgi_param SCRIPT_FILENAME D:\work\soft\php\www$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
php配置:
指定docroot——php檔案的存放目錄,即你的documentroot。doc_root = “F:/WAMP/www”
擴充存放目錄 extension_dir——更改為真實的擴充存放地址。extension_dir = “./ext”
預設時區更改——在[Date]裡面增加:date.timezone = Asia/ChongQing
因為nginx需要的是cgi方式的php,所以如下幾個地方是重點,否則nginx無法開啟php檔案:
enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
三、編輯 php與nginx啟動指令碼:
@echo off
set root= %~dp0
set php_home=%root%../../php-7.0.6-Win32-VC14-x86
set nginx_home=%root%
REM Windows 下無效
REM set PHP_FCGI_CHILDREN=5
REM 每個進程處理的最大請求數,或設定為 Windows 環境變數
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI... %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini
RunHiddenConsole %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini
echo Starting nginx... %nginx_home%/nginx.exe
RunHiddenConsole %nginx_home%/nginx.exe
如果運行過程中報:無法啟動此程式,因為電腦中丟失VCRUNTIME140.dll 嘗試重新安裝此程式以解決此問題
32位版下載地址:http://download.microsoft.com/download/9/E/1/9E1FA77A-9E95-4F3D-8BE1-4D2D0C947BA2/enu_INREL/vcredistd14x86/vc_redist.x86.exe
http://www.microsoft.com/en-us/download/details.aspx?id=46881
64位版下載地址:http://download.microsoft.com/download/9/E/1/9E1FA77A-9E95-4F3D-8BE1-4D2D0C947BA2/enu_INREL/vcredistd14x64/vc_redist.x64.exe
四、編輯 php與nginx停止指令碼:
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
五、在D:\work\soft\php\www下建立 index.php
<?php
2 echo "Hello PHP7!";
3 ?>
六、訪問瀏覽器
http://localhost/index.php