1 下载安装 nginx 和 php
nginx 官网
https://blog.51cto.com/transfer?http://nginx.org/en/download.html
php 官网
https://blog.51cto.com/transfer?http://windows.php.net/download/
本人使用的版本 nginx1.24.0, php8.2.10 Thread Safe版本
解压缩到 D:\Program Files\wnmp\ 目录
2 配置文件修改
1 nginx.conf 修改
D:\Program Files\wnmp\nginx-1.24.0\conf\nginx.conf 修改
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
大概 65-72行 放开注释,修改 fastcgi_param 一行 把 /scripts$fastcgi_script_name 改成$document_root$fastcgi_script_name
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 这里有修改,document_root指的是 nginx 根目录 html
include fastcgi_params;
}
2 php.ini
D:\Program Files\wnmp\php-8.2.10-Win32-vs16-x64\ 目录下 php.ini-development 修改为 php.ini 并编辑
extension_dir 一行去掉注释
enable_dl=Off 改为 On
cgi.force_redirect=1改为0
fastcgi.impersonate=1去掉注释
cgi.rfc2016_headers=0改为1
3 运行
nginx 的html 目录下 创建 1.php 文件
cmd 窗口 启动 php-cgi 和niginx
<?php phpinfo(); ?>
访问 http://127.0.0.1, nginx 访问成功
访问 http://127.0.0.1/1.php, 说明php 也调用成功<