Nginx在Linux上运行性能更高,不过有时候在Windows下测试需要安装Windows这里说一下具体安装步骤,首先准备安装所需要的软件,点此下载, 当然你也可以到官网下载最新版本,将php解压,例如我解压到D:/wnmp/php,你也可以根据需求解压到你喜欢的目录.将php.ini- recommended复制一份重新命名为php.ini打开将extension_dir = "./"更改为extension_dir ="D:/wnmp/php/ext",找到; cgi.fix_pathinfo=1将前面的分号和空格去掉.
接下来安装nginx,将nginx-1.0.4.zip解压,我也解压到D:/wnmp并且重命名为nginx,进入nginx/conf目录打开nginx.conf找到
location / {
root html;
index index.html index.htm;
}
root类似于apache的documentRoot,将其修改为你喜欢的目录,index是默认主页,可以修改为你喜欢的目录和文件名,例如我修改为如下
location / {
root D:/wnmp/htdocs;
index index.html index.htm index.php;
}
找到:
#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;
#}
将#都去掉
再将root html;改为root D:/wnmp/htdocs;
/scripts改为$document_root
下面来个修改后的完整的:
location ~ \.php$ {
root D:/wnmp/htdocs;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
将RunHiddenConsole.zip解压到nginx目录
创建启动脚本start.bat,输入如下代码
@echo off
REM Windows 下无效
REM set PHP_FCGI_CHILDREN=5
REM 每个进程处理的最大请求数,或设置为 Windows 环境变量
set PHP_FCGI_MAX_REQUESTS=1000
echo Starting PHP FastCGI...
D:/wnmp/nginx/RunHiddenConsole.exe D:/wnmp/php/php-cgi.exe -b 127.0.0.1:9000 -cD:/wnmp/php/php.ini
echo Starting nginx...
D:/wnmp/nginx/RunHiddenConsole.exe D:/wnmp/nginx/nginx.exe -p D:/wnmp/nginx
创建停止脚本 stop.bat 输入
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit
接下来执行一下start.bat看是否启动成功
stop.bat是停止nginx与cgi服务
为了能够运行项目,最后打开需要开启的扩展
在php.ini中找到
;extension=php_gd2.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_mbstring.dll
;extension=php_exif.dll
;extension=php_gettext.dll
;extension=php_pdo.dll
;extension=php_pdo_mysql.dll
;extension=php_mcrypt.dll
;extension=php_curl.dll
等将前面的分号去掉,然后停止在启动即可
注:如果没有mysql扩展可以尝试把php目录下的libmysql.dll文件复制到C:\Windows目录下
在windows下搭建nginx+php
最新推荐文章于 2022-11-08 10:48:59 发布