Windows 安装 Nginx 和 PHP(配置)

Windows 安装 Nginx 和 PHP(配置)_第1张图片

本文向您展示如何在Windows上安装和集成Nginx和PHP。

经过测试

  1. Nginx 1.12.1
  2. PHP 7.1.10
  3. Windows 10

1.安装Nginx + PHP

基本上,只需下载zip文件并解压缩即可,无需安装。

安装Nginx

  1. 访问http://nginx.org/en/download.html
  2. 下载nginx/Windows-1.12.2
  3. 提取到C:\nginx-1.12.1

安装PHP

  1. 访问http://windows.php.net/download/
  2. 下载PHP7.1下载VC14 x64非线程安全
  3. 解压到C:\php7.1.10

注意
此PHP VC14版本需要安装Visual Studio 2015的Visual C ++可再发行组件

2.集成Nginx + PHP

Nginx通过php-cgi.exe与PHP通信

2.1从127.0.0.1:9999启动PHP

Terminal
c:\php7.1.10>php-cgi.exe -b 127.0.0.1:9999

2.2编辑Nginx conf文件。

C:\nginx-1.12.1\conf\nginx.conf
http {
    include       mime.types;
    default_type  application/octet-stream;

    server {
        listen       80;
        server_name  localhost;

		# Declares here, so that $document_root is able to find php files
		root www;
		
        location / {
            index  index.html index.htm;
        }

		# For PHP files, pass to 127.0.0.1:9999
		location ~ \.php$ {
			fastcgi_pass   127.0.0.1:9999;
			fastcgi_index  index.php;
			fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
			include        fastcgi_params;
		}

    }

}

2.3创建一个C:\nginx-1.12.1\www文件夹。

2.4创建一个简单的PHP文件并将其放入www文件夹。

C:\nginx-1.12.1\www\print.php

2.5启动Nginx

Terminal
C:\nginx-1.12.1> start nginx

3.演示

http://localhost/print.php

Windows 安装 Nginx 和 PHP(配置)_第2张图片

做完了

参考文献

  1. Nginx官方网站
  2. Windows版PHP
  3. Windows上的PHP-FastCGI
  4. php-cgi.exe –应用程序无法正确启动
  5. Nginx + PHP –未指定输入文件
 

翻译自: https://mkyong.com/nginx/nginx-php-on-windows/

你可能感兴趣的:(Windows 安装 Nginx 和 PHP(配置))