LoginSignup
55
59

More than 5 years have passed since last update.

ApacheでPHP-FPMを動かすなら、ProxyPassMatchではなくSetHandlerを使うのがいいらしい

Posted at

タイトルの通り。

Apacheでmod_proxy_fcgiを使ってPHP-FPMを動かす場合、ProxyPassMatchを使う方法がある。

httpd.conf
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/path/to/your/documentroot/$1

しかしこの設定ではDirectoryIndexが効かなかったりPATH_INFOがおかしかったりと、様々な問題がある。

Ubuntu 14.04 の Apache mod_proxy_fcgi で php 動かすのは厳しい話 - はざまブログによると、Apache 2.4.10以降では以下の書き方ができるようになった。

httpd.conf
DirectoryIndex index.php index.html

<FilesMatch \.php$>
    SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>

ファイル名が.phpで終わる場合、127.0.0.1:9000で起動するFastCGI(=PHP-FPM)に処理を任せる、となる。わかりやすいし簡潔な設定になった。DirectoryIndexもきちんと効く。

Unixソケットを使っている場合は以下のようになる。

httpd.conf
<FilesMatch \.php$>
    SetHandler "proxy:unix:/var/run/php-fpm/php-fpm.sock|fcgi://localhost"
</FilesMatch>

HerokuのApache設定でも同じような書き方がされている。

参考

55
59
1

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
55
59