windows安装配置nginx php环境
(1)下载安装包
nginx安装包,下载稳定版 Stable version
官方下载地址:http://nginx.org/en/download.html
php安装包,PHP版本选择php8.0 (vs16 x64 Non Thread Safe)
https://windows.php.net/download/
PHP8.0需要的vc运行库安装包,如果是其它的版本的PHP请安装对应的VC运行库
VC运行库下载地址:https://aka.ms/vs/16/release/VC_redist.x64.exe
(2)配置PHP
解压PHP压缩包到D:\NPM\php目录
①配置php.ini
把php.ini-development重命名为php.ini
然后修改php.ini里的以下几个参数
short_open_tag = On
upload_tmp_dir= "C:\Windows\Temp"
session.save_path = "C:\Windows\Temp"
post_max_size = 300M
upload_max_filesize = 200M
date.timezone = PRC
extension_dir = "ext"
max_execution_time=60
max_input_vars=10000
cgi.fix_pathinfo=1
然后把下列几个扩展前面的分号“;”去掉
extension=curl
extension=gd
extension=fileinfo
extension=mbstring
extension=exif
extension=mysqli
extension=openssl
extension=pdo_mysql
②检测PHP配置
运行cmd,然后行以下命令
d:
cd D:\NPM\php
php -v
如果运行显示版本信息,没有报错,说明php.ini配置文件没有问题
nginx配置
解压nginx压缩包到 D:\NPM\nginx目录里
在d:\NPM\nginx\nginx.conf文件的http代码段内添加下列几个参数
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 200m;
在server代码段内添加php解析代码,并添加默认主页index.php
location ~ \.php(.*)$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
include fastcgi_params;
}
启动服务
在cmd命令里运行 ,两行命令都需要运行
D:\NPM\php\php-cgi.exe -b 127.0.0.1:9000 -c D:\NPM\php\php.ini
cd /d D:\NPM\nginx
D:\NPM\nginx\nginx.exe
在nginx下的html目录里新建test.php
<?php
phpinfo();
?>
在浏览器里输入localhost/test.php如果出现以下界面说明安装成功
添加启动脚本
先下载RunHiddenConsole解压到nginx目录里
下载地址:https://pan.baidu.com/s/1aziaIS4rTrJVs3Q-TrCBLQ
提取码:umlx
启动脚本,在nginx目录里新建为start.bat
@echo off
set PHP_FCGI_MAX_REQUESTS = 1000
echo Starting PHP FastCGI...
RunHiddenConsole D:\NPM\php\php-cgi.exe -b 127.0.0.1:9000 -c D:\NPM\php\php.ini
echo Starting nginx...
RunHiddenConsole D:\NPM\nginx\nginx.exe -p D:\NPM\nginx\
exit
停止脚本,在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
pause
如果需要开启运行start.bat即可,关闭则运行stop.bat