Windows下Nginx+php環境搭建
++++++++++++++++++++++++++++++++++++++++++++++
操作系統 : [windows xp professional sp3]
服務器 : [nginx-0.8.21]
PHP : [php-5.2.17]
++++++++++++++++++++++++++++++++++++++++++++++
準備安裝軟件(download)
1> [nginx-0.8.21]
http://sysoev.ru/nginx/nginx-0.8.21.zip
2> [php-5.2.17-Win32-VC6-x86]
http://windows.php.net/downloads/releases/php-5.2.17-Win32-VC6-x86.zip
3> [服務註冊工具(srvany.exe, instsrv.exe)]
http://download.csdn.net/detail/zy27ok/2248126
4> [RunHiddenConsole-Windows下隱藏DOS命令行窗口的程序]
http://ishare.iask.sina.com.cn/f/16990002.html
++++++++++++++++++++++++++++++++++++++++++++++
開始安裝(安裝前建立目錄[D:/lamp])
D:/lamp
--nginx
--php
--sites
----------------------------------------------------------------------------
1>【nginx】
1.1> 將nginx-0.8.21.zip解壓到[D:/lamp/nginx]中
1.2> 將nginx安裝到windows服務中
1.2.1>下載微軟服務註冊工具srvany.exe, instsrv.exe存放到D:/lamp/nginx/目錄下
1.2.2>安裝Nginx服務, 將命令行切換到D:/lamp/nginx/,執行下列命令
instsrv NGINX D:\lamp\nginx\srvany.exe
1.2.3>在D:/lamp/nginx/下,新建一個nginx.reg文件,輸入一下內容:Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NGINX\Parameters]
"Application"="D:/lamp/nginx/nginx.exe"
"AppParameters"=""
"AppDirectory"="D:/lamp/nginx/"
1.2.4>讓服務與程序關聯起來,命令行執行regedit /s nginx.reg2>【php】
2.1> 將php-5.2.17-Win32-VC6-x86.zip解壓到[D:/lamp/php]
3>【php配置】
3.1> php.ini
3.1.1> D:/lamp/php/php.ini, 複製php.ini-recommended並重命名爲php.ini
3.1.2>
#功能: 指定擴展庫所在目錄
extension_dir = "D:/lamp/php/ext/"
#功能: 開啓擴展#說明: 根據需要開啓相應擴展模塊, 去掉前前面的分號
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mcrypt.dll
extension=php_mysql.dll
extension=php_mysqli.dll
#功能: 設置時區#說明: PRC表示中國
date.timezone = PRC
#功能: 顯示錯誤信息display_errors = On
#功能: cgi相關 enable_dl = On
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
3.2>複製php5ts.dll, libmysql.dll, libmcrypt.dll(D:/lamp/php)到C:/WINDOWS/system32/4>【nginx配置】
4.1>在server下找到location / 修改解析PHP文件存放的路徑, 修改爲:
location / {
root D:/lamp/sites;
index index.html index.htm index.php;
}
root表示虛擬目錄設置爲D:/lamp/sites,增加默認解析index.php4.2>在server下找到location ~ /.php$ 修改php解釋器FastCGI配置,修改爲:
location ~ \.php$ {
root D:/lamp/sites;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME D:/lamp/sites$fastcgi_script_name;
include fastcgi_params;
}
5>【用命令行啓動或終止php-cgi和進程】5.1>下載RunHiddenConsole:用來隱藏dos窗口
5.2>啓動php-cgi,新建一個bat文件,如start.bat,用記事本打開,並編寫如下代碼:
@echo off
echo Starting PHP FastCGI...
RunHiddenConsole.exe D:/lamp/php/php-cgi.exe -b 127.0.0.1:9000 -c D:/lamp/php/php.ini
5.3>終止php和nginx進程,如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
6>【nginx基於域名的虛擬主機配置】
6.1>在http最後一行加入
include D:/lamp/nginx/conf/vhost/dev_localhost.config;
6.2>不帶url重寫:D:/lamp/nginx/conf/vhost/dev_localhost.config
server {
listen 80 default;
server_name dev.localhost;
access_log logs/dev.access.log;
root D:/lamp/sites/dev;
server_name_in_redirect off;
location / {
index index.html index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
6.3>帶url重寫(zend framework)D:/lamp/nginx/conf/vhost/dev_localhost.config
server {
listen 80;
server_name dev.localhost;
access_log logs/dev.access.log;
root D:/lamp/sites/dev/code/html;
location / {
index index.html index.php;
if (-e $request_filename ) {
break;
}
if ( $request_filename ~* \.(js|ico|gif|jpg|jpeg|xml|swf|txt|png|css|html|htm)$ ) {
return 404;
}
rewrite .* index.php;
}
location ~ .*\.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
#fastcgi_param REQUEST_URI $document_uri?$query_string;
fastcgi_read_timeout 120;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}