php-fpmとfastcgiを使ってphpを実行する


恒例

FastCGIに関して
https://ja.wikipedia.org/wiki/FastCGI

FPMに関して
http://php.net/manual/zh/install.fpm.php
https://php-fpm.org/

php-fpm Installation

Yumでインストールする

yum install php55w-fpm #php5.5の場合
yum install php56w-fpm #php5.6の場合
yum install php70w-fpm #php7.0の場合

自分でcompileでインストールする
--enable-fpmというペラメタつけてphpをコンパイルする
例えば

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs --with-zlib --with-mysql=mysqlnd --with-mysqli --enable-mbstring --enable-ftp --with-xsl --with-gd --with-jpeg-dir=/usr/local/libjpeg --with-png-dir=/usr/local/libpng --with-freetype-dir --with-pdo-mysql --with-openssl --enable-soap --with-mcrypt --enable-zip --with-tidy --with-curl --enable-gd-native-ttf --enable-bcmath --enable-sockets --enable-exif --with-gettext --with-ldap --enable-fpm --with-fpm-user=fpm-user --with-fpm-group=fpm-group

--enable-fpm
--with-fpm-user=fpm-user
--with-fpm-group=fpm-group

fpm-userとfpm-groupをサーバーのユーザーに替えてください

FastCGI Installation

Yumでインストールする
bash
yum install fcgi-devel fcgi

自分でcompileでインストールする
https://httpd.apache.org/mod_fcgid/ からmod_fcgidをダウンロードする

tar zxf mod_fcgid-2.3.9.tar.gz
cd mod_fcgid-2.3.9/
APXS=/usr/local/httpd/bin/apxs ./configure.apxs
make
make install

httpd.confを編集する


#追加する
LoadModule fcgid_module modules/mod_fcgid.so 
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

#追加する
<IfModule fcgid_module>
 AddHandler fcgid-script .php
 FcgidWrapper "/usr/local/php/bin/php-cgi" .php  #自分のphpのpathに替えてください
</IfModule>

#追加する
<IfModule fcgid_module>
 AddHandler fcgid-script .php
 AddHandler fcgid-script .fcgi
 FcgidWrapper "/usr/local/php/bin/php-cgi" .php  #自分のphpのpathに替えてください
 <FilesMatch \.php$>
  SetHandler "proxy:fcgi://127.0.0.1:9000"
 </FilesMatch>
</IfModule>

php-fpm.confを編集する

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = fpm-user
group = fpm-group

listen = 127.0.0.1:9000
; listen = /usr/local/php/var/run/socket

#socket と port 2つlisten方法がある、一つを選んでください

php-fpmをスタート

/usr/local/php/sbin/php-fpm

phpinfo()で確認する

Server API は FPM/FastCGIで表示されると成功!