nginxでphpを使えるようにした
php-fpmをインストールして使えるようにしたかったのだが、意外とハマってしまう箇所があった。
nginx側の設定に問題があったらしくて直したら使えるようになった。
- 最初の設定
... # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root [自分で指定したパス]; # fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ...
- 修正後
... # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root [自分で指定したパス]; # fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } ...
おわかりいただけただろうか
下の2行(include~とfastcgi_param~)を入れ替えたらうまく行ったのである
修正前の順番のまま載せてあるサイトが多いけどちゃんと動いてるのかな。仕様が変わったのかもしれない。