最近嘗試windows下配置nginx+php+mysql,在這裡總結一下。
1、下載windows版本的nginx,官網下載地址:http://nginx.org/en/download.htm,下載好後解壓到D:\wnmp
2、配置php
下載windows版本的php,官網下載地址:http://windows.php.net/download/,php將會以cgi的方式運行,解壓下載好的php包,到D盤wnmp目錄(D:\wnmp),這裡把解壓出來的文件夾重命名成php5。

進入文件夾修改php.ini-development文件為php.ini。

打開php.ini,找到以下代碼
extension_dir ="./ext"更改為extension_dir ="D:/wnmp/php5/ext"。
;extension=php_mysql.dll 去掉分號
;extension=php_mysqli.dll 去掉分號(打開數據庫動態鏈接庫)
然後把php5目錄下的libmysql.dll文件復制到C:\Windows目錄下,或者設置環境變量路徑也可以,然後找到以下代碼
;cgi.fix_pathinfo=0 去掉分號並改為 cgi.fix_pathinfo=1
3、配置nginx
解壓後打開conf目錄下的nginx.conf文件,找到
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# 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;
#}
改為:
location / {
root d:/www; //自行設置目錄
index index.html index.htm;
}
error_page 404 /404.html;
redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root d:/www;
}
proxy the PHP scripts to Apache listening on 127.0.0.1:80
location ~ \.php$ {
proxy_pass http://127.0.0.1;
}
pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root d:/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
保存配置文件。
4、運行nginx和php
輸入命令:
D:\wnmp\php5>php-cgi.exe -b 127.0.0.1:9000 -c D:/wnmp/php5/php.ini
以cgi的方式運行php,監聽nginx從9000端口發來的數據。雙擊nginx.exe運行nginx。
快捷啟動設置:先下載RunHiddenConsole.exe這個文件放入nginx目錄中,然後將以下代碼保存為start_nginx.bat
@echo off set php_home=../php5/ set nginx_home=./ echo Starting PHP FastCGI... RunHiddenConsole %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini echo Starting nginx... RunHiddenConsole %nginx_home%/nginx.exe -p %nginx_home% exit
將以下代碼保存為stop_nginx.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_nginx.bat就可以啟動nginx和php了。

5、安裝配置mysql 下載mysql:http://dev.mysql.com/downloads/mysql/,然後解壓到D:/mnmp目錄下 在my-default.ini中找到
basedir=C:\Program Files\MySQL\ 去掉#(mysql所在目錄)
datadir=C:\Program Files\MySQL\data 去掉#(mysql所在目錄\data)
命令行進入目錄:cd C:\Program Files\MySQL\bin,輸入以下命令安裝mysql:mysqld -install (安裝後可以在服務中找到)
啟動服務:net start mysql,關閉服務:net stop mysql 。也可以在服務中啟動或者關閉。
添加path變量:在計算機>屬性>高級系統中設置>環境變量中添加:F:\phpenv\mysql\bin 登錄命令:mysql -h 主機ip -u 用戶名 -p 用戶密碼