在Windows上安装Nginx并配置PHP的步骤如下:
下载Nginx:
.zip
文件)。解压Nginx:
.zip
文件解压到一个目录中,例如 C:\nginx
。启动Nginx:
bash
cd C:\nginx
bash
start nginx
http://localhost
,如果看到Nginx的欢迎页面,说明Nginx已经成功安装并运行。下载PHP:
Non Thread Safe
版本,因为Nginx不支持线程安全)。解压PHP:
.zip
文件解压到一个目录中,例如 C:\php
。配置PHP:
C:\php
目录下,复制 php.ini-development
文件并重命名为 php.ini
。php.ini
文件,找到并修改以下配置:
ini
extension_dir = "ext"
cgi.fix_pathinfo=1
extension=mysqli
、extension=gd2
等)。修改Nginx配置文件:
C:\nginx\conf\nginx.conf
。找到 server
块,修改或添加以下内容:
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
启动PHP FastCGI进程:
bash
cd C:\php
bash
php-cgi.exe -b 127.0.0.1:9000
创建PHP测试文件:
html
目录下(例如 C:\nginx\html
),创建一个名为 index.php
的文件,内容如下:
php
访问PHP测试页面:
http://localhost/index.php
,如果看到PHP的信息页面,说明PHP已经成功配置并运行。创建批处理文件:
start_nginx_php.bat
,内容如下:
bash
@echo off
start C:\nginx\nginx.exe
start C:\php\php-cgi.exe -b 127.0.0.1:9000
将批处理文件添加到启动项:
start_nginx_php.bat
文件复制到 C:\Users\<你的用户名>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
目录中,这样每次开机时Nginx和PHP都会自动启动。至此,你已经成功在Windows上安装并配置了Nginx和PHP。你可以开始开发和运行PHP应用程序了。
如果有任何问题或需要进一步的帮助,请随时提问!