LoginSignup
10
10

More than 5 years have passed since last update.

PHP-FPM(7.0.5)とnginx(1.8.1)

Last updated at Posted at 2016-04-24

環境

  • EC2
  • nginx (1.8.1)
  • PHP (7.0.5)

PHP-FPM(FastCGI Process Manager)

インストール

# yum install -y libicu-devel
# cd /usr/local/src/
# wget http://jp2.php.net/distributions/php-7.0.5.tar.bz2
# tar xvfj php-7.0.5.tar.bz2
# cd php-7.0.5
./configure --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --enable-mbstring --enable-opcache --enable-intl --with-zlib-dir
# make
# make install
# php-fpm -v
PHP 7.0.5 (fpm-fcgi) (built: Apr 24 2016 05:20:19)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

設定ファイル(php-fpm.conf)

# cp /usr/local/src/php-7.0.5/sapi/fpm/php-fpm.conf /etc/
/ect/php-fpm.conf
# vi /ect/php-fpm.ini
pid = /var/run/php-fpm.pid
include=/etc/php-fpm.d/*.conf

プロセスグループの設定

『PHP-FPMでは、複数の異なるアプリケーション設定のプロセスを同時に実行でき、同じ設定のプロセスグループをプロセスプールと呼びます』
ということらしいので、プロセスグループの設定を/etc/php-fpm.d/以下に配置

# mkdir /etc/php-fpm.d
# cp /usr/local/src/php-7.0.5/sapi/fpm/www.conf.in /etc/php-fpm.d/www.conf
/etc/php-fpm.d/www.conf
# vi /etc/php-fpm.d/www.conf
user = @php_fpm_user@
group = @php_fpm_group@
↓
user = nginx
group = nginx

起動スクリプト

# cp /usr/local/src/php-7.0.5/sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
# chmod 755 /etc/init.d/php-fpm
prefix=@prefix@
exec_prefix=@exec_prefix@

php_fpm_BIN=@sbindir@/php-fpm
php_fpm_CONF=@sysconfdir@/php-fpm.conf
php_fpm_PID=@localstatedir@/run/php-fpm.pid
↓
prefix=/usr/local
exec_prefix=${prefix}

php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=/etc/php-fpm.conf
php_fpm_PID=/var/run/php-fpm.pid
# chkconfig php-fpm on
# chkconfig | grep php-fpm
# /etc/init.d/php-fpm start

nginxインストール

  • 予めドキュメントルートを作成しておき、phpinfo()でも用意しておく
# mkdir /home/nginx/www
# echo '<?php phpinfo();' > /home/nginx/www/phpinfo.php
/etc/yum.repos.d/nginx.repo
#vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0                       
enable=1
# yum install nginx
# vi /etc/nginx/nginx.conf
/etc/nginx/nginx.conf
location / {
    root /home/nginx/www;
    index index.html;
}
location ~ \.php$ {
    root           /home/nginx/www;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
    include        fastcgi_params;
}
# /etc/init.d/nginx configtest
# /etc/init.d/nginx start
# /etc/init.d/nginx stop
# chkconfig --add nginx
# chkconfig --level 35 nginx on
# chkconfig --list | grep nginx

参照

10
10
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
10
10