LoginSignup
3
4

More than 3 years have passed since last update.

Docker CentOSイメージを使用してPHP-FPMを実行する

Posted at

CentOSイメージをベースにしてphp-fpmが動作するコンテナを作成します。サンプルです。

リポジトリ
https://github.com/kakizaki/sample_docker_phpfpm_cent

動機

DockerHubにはphp-fpmのための公式のイメージがありますが、ベースはdebianまたはalpineだったと思います。
実際のサーバー環境はCentOSを使用していて、yumによりパッケージをインストールをしています。
コンテナでもyumが使えて、同じように書けると楽です。

使用手順

docker-compose upを実行すると、nginxコンテナとphp_fpmコンテナが起動します。
ブラウザでhttp://localhost/index.phpを表示すると、phpinfoの実行結果が表示されると思います。

はまった点

php-fpmの設定を誤っていたことで、nginxコンテナからphp_fpmコンテナへアクセスできずに、はまってしまいました。
(unixソケットを使用する場合には不要ですが)

php/www.conf
; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
; HACK 外部からのアクセスを許す場合はコメント(any)にするか、IPを指定する
;listen.allowed_clients = 127.0.0.1
3
4
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
3
4