IT業界のすみっこ暮らし

ふと気がついたときの記録



win10 + php5 + nginxローカル環境設定

参照

Windows10(64Bit版)にApache2.4、PHP5.6をインストールする方法

↑はPHPのインストールのみ参照

Windows10にnginx+PHP環境の構築(初心者の復習用)

1. phpダウンロード

https://windows.php.net/downloads/releases/archives/

2. PHPをダウンロードして、適当にzipファイルを解凍した後

f:id:papamau:20180720190348p:plain

3. フォルダ名を[php5]に変更後、[C:\Program Files (x86)]にコピー。(C:\Program Files (x86)\php5)

f:id:papamau:20180720190409p:plain

4. 環境変数[path]に[C:\Program Files (x86)\php5]追加

f:id:papamau:20180720190426p:plain

5. [php -v]でインストール確認

f:id:papamau:20180720190459p:plain

6. php.ini ファイル作成

[C:\Program Files (x86)\php5\php.ini-development]をコピーして名前を[php.ini]に変更する。

以下、最小限の変更箇所

; extension_dir = "ext"
↓
extension_dir = "C:\Program Files (x86)\php5\ext"

※コメント解除

;extension=php_gd2.dll
;extension=php_mbstring.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
↓
extension=php_gd2.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll

7. [nginx/Windows-1.10.3 ]リンクからダウンロード

nginx: download

8. zipファイルを解凍して下記に格納。(どこでもいい)

C:\server\nginx-1.10.3

f:id:papamau:20180720190702p:plain

8-1. ファイアウォールの通信を許可(不要かもしれないが私はやった)

f:id:papamau:20180720190754p:plain

9. [C:\server\nginx-1.10.3\conf\nginx.conf]を修正

#user  nobody;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        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;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

10. [localhost]にアクセスしてnginxの画面が表示されれば一応nginxはok.

nginx起動(nginx.exeが格納されているフォルダ内で実行)

f:id:papamau:20180720190903p:plain

START nginx.exe

リクエスト処理後停止

f:id:papamau:20180720190919p:plain

nginx.exe -s quit

強制停止

f:id:papamau:20180720190936p:plain

nginx.exe -s stop

f:id:papamau:20180720190944p:plain

11. [php-cgi]を起動してphpファイルが正常に動作するか確認。

php-cgi起動

START php-cgi.exe -b 127.0.0.1:9000 -c C:\php\php.ini

※-cコマンドで参照するconfigを指定可能。指定しない場合、[Loaded Configuration File]に[(none)]が表示され、拡張モジュール(extension)の読み込みなどが出来ないので、下記のtest.phpでphpの設定を確認する。

test.php

<?php
  phpinfo();
?>

php-cgi停止

Taskkill /im php-cgi.exe

f:id:papamau:20180720191044p:plain

開発するならもっともりもり設定を見なきゃだけど、一応最低限ここまででhello worldはできるようになった。

追記

PHPに[mysqli]の拡張モジュールがインストール済みなのにMySQLにアクセスできない場合、下記の[mysqli.default_socket]の値の設定漏れの場合があるので調べながら頑張る。 f:id:papamau:20180724111404p:plain





プライバシーポリシー