win7下搭建nginx+php的开发环境
一、下载相关软件
nginx下载:http://nginx.org/en/download.html
nginx常见异常:http://feiger.cn/?p=2719
php下载:http://windows.php.net/download#php-7.0
下载runhiddenconsole:http://www.xdowns.com/soft/1/71/2012/soft_89261.html
二、配置
nginx.conf文件,我的编辑结果如下所示,具体配置过程中需要注意什么请看注释:
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
root d:\work\soft\php\www;#网站目录
index index.html index.php;#加上对php的支持
autoindex on;#如果文件不存在列出目录结构;
}
location ~ \.php$ {
root d:\work\soft\php\www;
fastcgi_param script_filename d:\work\soft\php\www$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
php配置:
指定docroot——php文件的存放目录,即你的documentroot。doc_root = “f:/wamp/www”
扩展存放目录 extension_dir——更改为真实的扩展存放地址。extension_dir = “./ext”
默认时区更改——在[date]里面增加:date.timezone = asia/chongqing
因为nginx需要的是cgi方式的php,所以如下几个地方是重点,否则nginx无法打开php文件:
enable_dl = on
cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1
cgi.rfc2616_headers = 1
三、编辑 php与nginx启动脚本:
@echo off
set root= %~dp0
set php_home=%root%../../php-7.0.6-win32-vc14-x86
set nginx_home=%root%
rem windows 下无效
rem set php_fcgi_children=5
rem 每个进程处理的最大请求数,或设置为 windows 环境变量
set php_fcgi_max_requests=1000
echo starting php fastcgi... %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini
runhiddenconsole %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini
echo starting nginx... %nginx_home%/nginx.exe
runhiddenconsole %nginx_home%/nginx.exe
如果运行过程中报:无法启动此程序,因为计算机中丢失vcruntime140.dll 尝试重新安装此程序以解决此问题
32位版下载地址:http://download.microsoft.com/download/9/e/1/9e1fa77a-9e95-4f3d-8be1-4d2d0c947ba2/enu_inrel/vcredistd14x86/vc_redist.x86.exe
http://www.microsoft.com/en-us/download/details.aspx?id=46881
64位版下载地址:http://download.microsoft.com/download/9/e/1/9e1fa77a-9e95-4f3d-8be1-4d2d0c947ba2/enu_inrel/vcredistd14x64/vc_redist.x64.exe
四、编辑 php与nginx停止脚本:
@echo off
echo stopping nginx...
taskkill /f /im nginx.exe > nul
echo stopping php fastcgi...
taskkill /f /im php-cgi.exe > nul
exit
五、在d:\work\soft\php\www下创建 index.php
<?php
2 echo "hello php7!";
3 ?>
六、访问浏览器
http://localhost/index.php
上一篇: 跟我学OpenResty(Nginx+Lua)开发目录贴
下一篇: 网站架构经验随笔