0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

WSL Ubuntu上でのNginx + Php-fpm設定注意点

Last updated at Posted at 2017-12-04

2018/11/9追記

nginx.confに「fastcgi_buffering off;」を追記で、nginx+php-fpmが無限ロードする事なく動作するようになります。

参考になったURL
https://stackoverflow.com/questions/46286420/php7-0-fpm-extremly-slow-on-ubuntu-windows-subsystem-linux

以下、過去の失敗内容

本文はインストール方法の記事ではない。2017/12/3時点でのWSLへのツール検証結果の備忘録。

1. 表題を全てaptでインストール

バージョン指定のインストール方法は割愛。というかろくに控えていない。

2. NginxとPhp-fpmの連携設定

nginxの設定とポイント

  • php側のデフォルトuser/groupが「www-data」権限で動く為、それに合わせる
  • php関連の記述は「snippets/fastcgi-php.conf」に集約されている
$ vi /etc/nginx/nginx.conf

# 以下の1行を追記
user  www-data;↲
〜省略

http {↲
   〜省略

   server {↲
       location ~ \.php$ {↲
            root     /usr/share/nginx/html;↲

            #以下の1行を追記
            include  snippets/fastcgi-php.conf;↲
        }↲
}

nginxのphp-fpm設定とポイント

  • fastcgi_pass行はnginxとphpの接続方法。TCP接続「127.0.0.1:9000」よりも「*.sock」接続の方が速くなる
  • ソケットの参照先は「/var/run/」「/run/」どちらでも一緒(どちらも同じ参照元になる)
$ vi /etc/nginx/snippets/php-fpm.conf

# 以下の2行を追記
# fastcgi_pass   127.0.0.1:9000;↲
fastcgi_pass  unix:/var/run/php/php-fpm.sock;↲

# regex to split $uri to $fastcgi_script_name and $fastcgi_path↲
fastcgi_split_path_info ^(.+\.php)(/.+)$;↲

# Check that the PHP script exists before passing it↲
try_files $fastcgi_script_name =404;↲

# Bypass the fact that try_files resets $fastcgi_path_info↲
# see: http://trac.nginx.org/nginx/ticket/321↲
set $path_info $fastcgi_path_info;↲
fastcgi_param PATH_INFO $path_info;↲

fastcgi_index index.php;↲
include fastcgi.conf;↲
}

php-fpmの設定とポイント

  • ソケットを扱う権限はnginxでも設定した「www-data」にする
  • ソケットの参照先は「/var/run/」「/run/」どちらでも一緒(どちらも同じ参照元になる)
$ vi /etc/php/7.2/fpm/pool.d/www.conf

# 該当箇所を下記で設定
user = www-data↲
group = www-data↲

listen = /var/run/php/php-fpm.sock↲

listen.owner = www-data↲
listen.group = www-data↲
listen.mode = 0660↲

設定結果

結果から言うとダメ。静的ファイル(html等)は問題ないけれど、
phpファイルをブラウザで見た場合、タイムアウトまたは自分から中断しない限りファイルの読込が終わらない。
※ページ内容自体は表示される。http結果も200が返ってくる
※ページ内容はphpinfo()とかの単純な内容のもの

ソケット接続が悪いのかと思い、TCP接続にした場合も同様。
導入がミスってるのかWSLの問題なのか良く分からないし、ググっても同様の症例が検索に出てこない・・・

取り敢えず、次はbrewを使っていれてみる。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?