window+nginx+php环境配置

准备工作

下载 Nginx Windows版并解压
下载 PHP Windows版 并解压

下载RunHiddenConsole.zip 并解压

nginx配置

修改nginx目录的nginx.conf配置文件

#修改root目录,添加index.php
location / {
    root   D:/wnmp/nginx-1.12.2/html;
    index  index.html index.htm index.php;
}

#去掉注释,修改root目录,/scripts改成$document_root
location ~ \.php$ {
    root           D:/wnmp/nginx-1.12.2/html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

执行nginx.exe即可启动

php配置

复制一份php.ini-development改为php.ini

#去掉注释
extension_dir = "./ext"

...

#去掉注释
cgi.fix_pathinfo=1

cgi.fix_pathinfo开启php的cgi设置,这一步非常重要,让php能够与nginx结合

命令行执行:php-cgi.exe -b 127.0.0.1:9000,启动php

启动和停止脚本

手动启动很麻烦,所以使用脚本来方便管理启动和停止,需要RunHiddenConsole配置使用

start_nginx.bat 启动(注意修改目录):

@echo off  
set php_home=D:/wnmp/php-7.1.11/
set nginx_home=D:/wnmp/nginx-1.12.2/

echo Stopping nginx...    
taskkill /F /IM nginx.exe > nul  
echo Stopping PHP FastCGI...  
taskkill /F /IM php-cgi.exe > nul    
  
REM Windows 下无效  
REM set PHP_FCGI_CHILDREN=5  
  
REM 每个进程处理的最大请求数,或设置为 Windows 环境变量  
set PHP_FCGI_MAX_REQUESTS=1000  
  
echo Starting PHP FastCGI...  
RunHiddenConsole %php_home%/php-cgi.exe -b 127.0.0.1:9000 -c %php_home%/php.ini  
   
echo Starting nginx...  
RunHiddenConsole %nginx_home%/nginx.exe -p %nginx_home%  

pause

stop_nginx.bat 停止:

@echo off  
echo Stopping nginx...    
taskkill /F /IM nginx.exe > nul  
echo Stopping PHP FastCGI...  
taskkill /F /IM php-cgi.exe > nul  
pause

注意:start_nginx.bat,stop_nginx.bat和RunHiddenConsole.exe要在同级目录

window+nginx+php环境就配置好了

爱生活,爱技术

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注