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…
|