最近尝试windows下配置nginx+ph,在这里总结一下。
1、下载windows版本的nginx,官网?下载地址:http://nginx.org/en/download.htm
?下载windows版本的php,官网下载地址:http://windows.php.net/download/,php将会以cgi的方式运行
?2、配置php
解压下载好的php包,到F盘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=../php/ 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了。
时间: 2024-10-09 15:02:39