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{
listen80;
server_namelocalhost;
charsetutf-8;
location/{
rootD:\work\soft\php\www;#网站目录
indexindex.htmlindex.php;#加上对php的支持
autoindexon;#如果文件不存在列出目录结构;
}
location~\.php${
rootD:\work\soft\php\www;
fastcgi_paramSCRIPT_FILENAMED:\work\soft\php\www$fastcgi_script_name;
fastcgi_indexindex.php;
fastcgi_pass127.0.0.1:9000;
includefastcgi_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启动脚本:
@echooff
setroot=%~dp0
setphp_home=%root%../../php-7.0.6-Win32-VC14-x86
setnginx_home=%root%
REMWindows下无效
REMsetPHP_FCGI_CHILDREN=5
REM每个进程处理的最大请求数,或设置为Windows环境变量
setPHP_FCGI_MAX_REQUESTS=1000
echoStartingPHPFastCGI... %php_home%/php-cgi.exe-b127.0.0.1:9000-c%php_home%/php.ini
RunHiddenConsole%php_home%/php-cgi.exe-b127.0.0.1:9000-c%php_home%/php.ini
echoStartingnginx... %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停止脚本:
@echooff
echoStoppingnginx...
taskkill/F/IMnginx.exe>nul
echoStoppingPHPFastCGI...
taskkill/F/IMphp-cgi.exe>nul
exit
五、在D:\work\soft\php\www下创建index.php
<?php
2echo"HelloPHP7!";
3?>
六、访问浏览器
http://localhost/index.php