windows下ngx+php配置

 

下载环境

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如果界面中显示出你想要的结果就说明配置成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ngx_php功能是为nginx模块嵌入php脚本语言。别名为php-nginx-module。 特性 * 支持加载php.ini配置文件 * 支持原生php的全局变量$_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_SESSION... * 支持运行php代码与文件 * 支持RFC 1867文件上传协议 * 支持php错误输出 * 支持加载与运行PECL扩展 * 支持nginx的API在php中调用 环境 - PHP 5.3.*     PHP 5.4.*     PHP 5.5.*     PHP 5.6.* - nginx-1.4.7     nginx-1.6.3     nginx-1.8.1     nginx-1.9.15 安装 git clone https://github.com/rryqszq4/ngx_php.git wget 'http://nginx.org/download/nginx-1.6.3.tar.gz' tar -zxvf nginx-1.6.3.tar.gz cd nginx-1.6.3 export PHP_BIN=/path/to/php/bin export PHP_INC=/path/to/php/include/php export PHP_LIB=/path/to/php/lib ./configure --user=www --group=www \             --prefix=/path/to/nginx \             --with-ld-opt="-Wl,-rpath,$PHP_LIB" \             --add-module=/path/to/ngx_php/dev/ngx_devel_kit \             --add-module=/path/to/ngx_php 概要 user www www; worker_processes  4; events {     worker_connections  1024; } http {     include       mime.types;     default_type  application/octet-stream;     keepalive_timeout  65;          client_max_body_size 10m;        client_body_buffer_size 4096k;     php_ini_path /usr/local/php/etc/php.ini;     server {         listen       80;         server_name  localhost;              location /php {             content_by_php '                 echo "hello ngx_php";             ';         }     } } 标签:ngxphp

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值