image

この記事では、WindowsにNginxとPHPをインストールして統合する方法を説明します。

テスト済み

  1. Nginx 1.12.1

  2. PHP 7.1.10

  3. ウィンドウズ10

1. Nginx + PHPをインストールする

基本的には、zipファイルをダウンロードしてそれを抽出します。

2. Nginx PHPを統合する

Nginxは `php-cgi.exe`経由でPHPと通信します

2.1 PHPを `127.0.0.1:9999`で起動する

ターミナル

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

<?php
    phpinfo();
?>

2.5 Nginxを起動する

ターミナル

C:\nginx-1.12.1> start nginx

デモ


image

完了しました。

参考文献

Windows上で]。リンク://nginx/php-cgi-exe-the-application-was-started-to-start-exactly/[php-cgi.exe

  • アプリケーションが正常に起動することができませんでした]。リンク://nginx/nginx-php-no-input-file-specified/[Nginx PHP – 入力なし

指定されたファイル]