Nginx + PHP в Windows

Nginx + PHP в Windows

image

В этой статье показано, как установить и интегрировать Nginx и PHP в Windows.

проверенный

  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: ginx-1.12.1

Чтобы установить PHP

  1. Посетитеhttp://windows.php.net/download/

  2. Загрузить PHP7.1 Загрузить VC14 x64 Non Thread Safe

  3. Извлечь вC:\php7.1.10

Note
Эта сборка PHP VC14 требует наличия установленногоVisual C++ Redistributable for Visual Studio 2015

2. Интегрировать Nginx + PHP

Nginx взаимодействует с PHP черезphp-cgi.exe

2.1 Start PHP at 127.0.0.1:9999

Терминал

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

2.2 Edit Nginx conf file.

ginx.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 Create a C: ginx-1.12.1\www folder.

2.4 Create a simple PHP file and put it into the www folder.

ginx-1.12.1 \ www \ print.php

2.5 Start Nginx

Терминал

C:\nginx-1.12.1> start nginx

3. Demo

image

Готово.