第一部分:準備工作。(系統:Windows 7 64)
1.首先是下載下傳軟體。
NGINX-1.8.1官網下載下傳:http://nginx.org/download/nginx-1.8.1.zip
PHP5.6.15版本下載下傳位址:https://sourceforge.net/projects/xampp/files/latest/download
Mysql版本(XAMPP內建包)
2.安裝mysql軟體。
3.解壓縮xampp到自己目錄(D:/xampp)。
4.解壓NGINX你自己安裝位置(D:/nginx-1.8.1)。
第二部分:安裝nginx
1.打開D:/nginx-1.8.1目錄,運作該檔案夾下的nginx.exe
2.測試是否啟動nginx。打開浏覽器通路http://localhost 或 http://127.0.0.1,看看是否出現“Welcome to nginx!”,出現的證明已經啟動成功了。沒有啟動的話,看看80端口有占用沒。
注意:該網站的預設目錄在“D:/nginx-1.8.1/nginx/htm”l下

第三部分:安裝php(這裡主要講nginx配置啟動php,以cgi運作php)
nginx配置檔案是conf檔案夾裡的nginx.conf
1.修改大概第43~45行之間的
location /{
root html;
index index.html index.htm;}
修改網站檔案的路徑,以及添加index.php的預設頁。
location / {
root D:/nginx-1.8.1/basic/web;
index index.html index.htm inde.php;
}
2.支援php的設定
修改大概在第63-71行的
# 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;
#}
先将前面的“#”去掉,同樣将root html;改為root C:/wnmp/nginx-1.5.8/html;。再把“/scripts”改為“$document_root”,這裡的“$document_root”就是指前面“root”所指的站點路徑,這是改完後的:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root D:/nginx-1.8.1/basic/web;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#}
3.C:\wnmp\php\ext下修改php.ini-development檔案,将檔案名修改為php.ini,打開php配置檔案php.ini,儲存即可。
搜尋“extension_dir”,找到: e;xtension_dir = "ext" 先去前面的分号再改為 extension_dir = "C:\wnmp\php\ext"
搜尋“date.timezone”,找到:;date.timezone = 先去前面的分号再改為 date.timezone = Asia/Shanghai
搜尋“enable_dl”,找到:enable_dl = Off 改為 enable_dl = On
搜尋“cgi.force_redirect” ;cgi.force_redirect = 1 先去前面的分号再改為 cgi.force_redirect = 0
搜尋“fastcgi.impersonate”,找到: ;fastcgi.impersonate = 1 去掉前面的分号
搜尋“cgi.rfc2616_headers”,找到:;cgi.rfc2616_headers = 0 先去前面的分号再改為 cgi.rfc2616_headers = 1
搜尋“php_mysql”,找到:”extension=php_mysql.dll和extension=php_mysqli.dll 去掉前面的“;”extension=php_mysql.dll和extension=php_mysqli.dll (支援MYSQL資料庫)
其他的配置請按照自己的需求更改。
第三部分試運作以及編輯運作配置檔案
D:/xampp/php>php-cgi.exe -b 127.0.0.1:9000 -c php.ini
重新運作nginx.exe。
D:\nginx-1.8.1\basic\we此處的basic是yii架構的測試項目,
通路http://localhost/index.php
或者http://127.0.0.1/index.php
出現如下的資訊就說明php已經成功安裝:
開啟php-cgi和nginx.exe,儲存為start.bat
@echo off
echo Starting PHP FastCGI...
C:\wnmp\nginx\RunHiddenConsole.exe C:\wnmp\PHP\php-cgi.exe -b 127.0.0.1:9000-c D:\PHP\php.ini
echo Starting nginx...
C:\wnmp\nginx\RunHiddenConsole.exe D:/nginx/nginx.exe -p D:/nginx
停止php-cgi和nginx.exe,儲存為stop.bat
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit