windows下ngx+php配置

来源:互联网 发布:战棋游戏 知乎 编辑:程序博客网 时间:2024/05/21 21:49
 

下载环境

1.       http://windows.php.net/download/中下载PHP 5.2 (5.2.17)  VC6 X86 THTREAD SAFE版本php。

2.       http://nginx.org/en/download.html中下载NGX的windows版可执行程序。

3.       下载RunHiddenConsole.exe程序

 

NGX配置

       解压NGX,在NGX的CONFIG目录中找到nginx.conf文件对该文件进行如下配置。

a)         location / {

root html;

index index.html index.htm;

}

改成

location / {

root webdir;

index index.html index.htm index.php;

};

其中root html改成root webdir指定是现在的WEB目录变成了webdir这个目录了,如果这个路径是绝对路径的话则要把\改成/;index.php为增加index.php为默认站点。

b)        #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 ~ \.php${

root webdir;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME D:/nginx/webdir$fastcgi_script_name;

include fastcgi_params;

}

     其中root html改成root webdir和(a)中所该的目录必须一致;/scripts改成d:/nginx/webdir是改成webdir的绝对路径,并且必须用/代替\。

 

PHP配置

     解压PHP,并且找到php目录中的php.ini-recommended,把其复制一份,并改名为php.ini;把php.ini中的; cgi.fix_pathinfo =1注释去掉,改成cgi.fix_pathinfo =1

 

 

 

编写启动和停止脚本

   新建一个start.bat文件,用来启动php-cgi.exe;里面脚本如下:

   @echo off

   echo Starting PHP FastCGI...

   RunHiddenConsole.exe /php/php-cgi.exe -b 127.0.0.1:9000 -c php/php.ini

   Pause

   注意要修改红线部分的路径,不然php-cgi.exe会启动不成功。

 

   新建一个stop.bat文件,用来停止php和ngx程序,脚本如下:

   @echo off

   echo Stopping nginx...

   taskkill /F /IM nginx.exe > nul

   echo Stopping PHP FastCGI...

   taskkill /F /IM php-cgi.exe > nul

   pause

 

启动服务

   启动前先运行stop.bat,之后运行start.bat,再运行nginx.exe程序。

 

测试

   编写一个php脚本,命名为index.php,放入webdir目录中,然后输入http://localhost如果界面中显示出你想要的结果就说明配置成功。