CentOS 7では、複数バージョンのPHPをコンパイルし、同時に実行し、システムの設定を行います.


CentOS 7の最大の変更点は、システムdが過去のシステムVサービスに代わることであり、サービスを構成する方法が変更され、システムctlが過去のサービス、chkconfigなどのコマンドに代わる.
ウェブサイトはサーバーを移転して、新しいサーバーはもちろん新しいシステムを使って、そこでCentOS 7をインストールします.
PHP5.4コンパイルパラメータ:
./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu \
--with-layout=GNU \
--prefix=/usr/local --exec-prefix=/usr/local  \
--sysconfdir=/etc  --libdir=/usr/local/lib/php \
--sbindir=/usr/local/sbin --sharedstatedir=/usr/com --datadir=/usr/local/share \
--includedir=/usr/local/include --libexecdir=/usr/local/libexec \
--localstatedir=/run --mandir=/usr/local/share/man --infodir=/usr/local/share/info \
--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d \
--with-pic  --with-curl  --with-freetype-dir --with-png-dir  \
--with-gettext=shared --with-gmp=shared --with-iconv --with-jpeg-dir --with-png-dir \
--with-openssl --with-libxml-dir --with-pcre-regex \
--with-mcrypt --with-zlib  --with-mhash \
--with-pear --with-gd --enable-gd-native-ttf --enable-calendar=shared \
--enable-exif --enable-ftp --enable-sockets --enable-bcmath=shared \
--enable-pcntl \
--enable-intl --enable-mbstring \
--enable-zip --with-bz2 \
--without-unixODBC --enable-mbregex \
--enable-fpm  --with-fpm-user=www  --with-fpm-group=www \
--disable-tokenizer --disable-phar \
--enable-sysvsem --enable-sysvshm --enable-sysvmsg \
--disable-cgi \
 \
--with-pgsql=/usr/pgsql-9.4 --with-pdo-pgsql=/usr/pgsql-9.4 \
 \
--with-pdo-mysql --with-mysql --with-mysql-sock=/var/lib/mysql/mysql.sock  \
--with-mysqli=shared --enable-mysqlnd \
 \

nginx1.8.0コンパイルパラメータ
./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf \
  --sbin-path=/usr/local/sbin/nginx --user=nginx --group=www \
  --with-http_ssl_module --with-http_realip_module  \
  --with-http_stub_status_module \
  --with-file-aio \
  --pid-path=/run/nginx.pid \
  --lock-path=/run/nginx/nginx.lock \
  --http-log-path=/var/log/nginx/access.log \
  --error-log-path=/var/log/nginx/error.log \
  --http-client-body-temp-path=/run/nginx/client \
  --http-proxy-temp-path=/run/nginx/proxy \
  --http-fastcgi-temp-path=/run/nginx/fcgi \
  --with-debug \
  --without-http_ssi_module \
  --without-http_scgi_module \
  --without-http_uwsgi_module \
  --without-http_autoindex_module \
  --without-http_memcached_module \
  --without-http_proxy_module \
  --without-http_map_module \
  --without-http_geo_module \
  --without-http_auth_basic_module \
  --without-http_upstream_ip_hash_module \
  --without-http_split_clients_module \
  --without-select_module \

/etc/php-fpm.conf:
[global]
pid = /run/php-fpm/php-fpm.pid
error_log = /var/log/php-fpm.log
log_level = warning
emergency_restart_threshold = 10
emergency_restart_interval = 60
process_control_timeout = 300s
daemonize = yes
rlimit_files = 10240

[www0]
prefix = /run/php-fpm/pools/$pool
listen = /run/php-fpm/php-fpm0.sock
listen.backlog = 2048
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 30
pm.max_requests = 500
pm.status_path = /status
request_terminate_timeout = 600
request_slowlog_timeout = 30
slowlog = /var/log/nginx/slow.log
env[TMP] = /run/php-fpm/tmp
env[TMPDIR] = /run/php-fpm/tmp
env[TEMP] = /run/php-fpm/tmp 

[www1]
prefix = /run/php-fpm/pools/$pool
listen = /run/php-fpm/php-fpm1.sock
listen.backlog = 2048
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 10
pm.max_requests = 500
pm.status_path = /status
request_terminate_timeout = 600
request_slowlog_timeout = 30
slowlog = /var/log/nginx/slow.log
env[TMP] = /run/php-fpm/tmp
env[TMPDIR] = /run/php-fpm/tmp
env[TEMP] = /run/php-fpm/tmp

php-fpm起動プロファイルの編集/etc/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
Before=nginx.service

[Service]
Type=forking
#Type=notify
PIDFile=/run/php-fpm/php-fpm.pid
ExecStart=/usr/local/sbin/php-fpm --fpm-config /etc/php-fpm.conf 
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 /etc/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server @ifxdb
After=network.target remote-fs.target nss-lookup.target php-fpm.service

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/local/sbin/nginx -t
ExecStart=/usr/local/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
PrivateTmp=true

[Install]
WantedBy=multi-user.target

仮想ファイル構成の編集(Centos 7の/runはtmpfsで接続されており、再起動するとディレクトリが消え、指定されたデフォルトが再生成されます)
/etc/tmpfiles.d/php-fpm.conf
#  systemd tmpfile settings for php-fpm and nginx
# See tmpfiles.d(5) for details


d /run/nginx 0755 nginx root - -
d /run/nginx/client 0755 nginx root 10d -
d /run/nginx/fcgi 0755 nginx root 10d -
d /run/nginx/proxy 0755 nginx root 10d -
d /run/nginx/cache0 0755 nginx root 10d -
d /run/nginx/cache1 0755 nginx root 10d -
d /run/nginx/cache2 0755 nginx root 10d -
d /run/nginx/cache3 0755 nginx root 10d -

d /run/php-fpm 0755 www www 10d -
d /run/php-fpm/tmp 0755 www www 3d -
d /run/php-fpm/session 0755 www www 1d -
d /run/php-fpm/pools 0755 www www 3d -
d /run/php-fpm/pools/www0 0755 www www - -
d /run/php-fpm/pools/www1 0755 www www - -
d /run/php-fpm/pools/www2 0755 www www - -
d /run/php-fpm/pools/www3 0755 www www - -

d /run/pear 0755 www www 3d -
d /run/pear/tmp 0755 www www 3d -

サーバーの再起動
コンパイル構成が完了しました.サービスの有効化と開始
sudo systemctl daemon-reload
sudo systemctl enable nginx php-fpm
sudo systemctl start nginx php-fpm

---------------------------------------------------------------------
PHP5.4少し年を取って、最新の安定版5.6を詰めてみて、間もなく来るPHP 7のために準備します.以前は1台のサーバでテストをしていましたが、今は1台のサーバでどのように設定すればいいですか?
まずPHP 5をコンパイルする.6,接頭辞が/optになっていることに注意
./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu \
--with-layout=GNU \
--prefix=/opt/local --exec-prefix=/opt/local  \
--sysconfdir=/etc  --libdir=/opt/local/lib/php \
--sbindir=/opt/local/sbin --sharedstatedir=/usr/com --datadir=/opt/local/share \
--includedir=/opt/local/include --libexecdir=/opt/local/libexec \
--localstatedir=/run --mandir=/opt/local/share/man --infodir=/opt/local/share/info \
--with-config-file-path=/opt --with-config-file-scan-dir=/opt/php.d \
--enable-opcache --with-fpm-acl \
--with-pic  --with-curl  --with-freetype-dir --with-png-dir  \
--with-gettext=shared --with-gmp=shared --with-iconv --with-jpeg-dir --with-png-dir \
--with-openssl --with-libxml-dir --with-pcre-regex \
--with-mcrypt --with-zlib  --with-mhash \
--with-pear --with-gd --enable-gd-native-ttf --enable-calendar=shared \
--enable-exif --enable-ftp --enable-sockets --enable-bcmath=shared \
--enable-pcntl \
--enable-intl --enable-mbstring \
--enable-zip --with-bz2 \
--without-unixODBC --enable-mbregex \
--enable-fpm  --with-fpm-user=www  --with-fpm-group=www  --with-fpm-systemd \
--disable-tokenizer --disable-phar \
--enable-sysvsem --enable-sysvshm --enable-sysvmsg \
--disable-cgi \
 \
--with-pgsql=/usr/pgsql-9.4 --with-pdo-pgsql=/usr/pgsql-9.4 \
 \
--with-pdo-mysql --with-mysql --with-mysql-sock=/var/lib/mysql/mysql.sock  --enable-mysqlnd \
 \

次に/etc/php-fpm 2を編集する.conf、php-fpm 2に注意.pid
pid = /run/php-fpm/php-fpm2.pid
; .......   [www0] [www1]  ,     

[www2]
prefix = /run/php-fpm/pools/$pool
listen = /run/php-fpm/php-fpm2.sock
listen.backlog = 2048
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 20
pm.max_requests = 500
pm.status_path = /status
request_terminate_timeout = 600
request_slowlog_timeout = 30
slowlog = /var/log/nginx/slow.log
env[TMP] = /run/php-fpm/tmp
env[TMPDIR] = /run/php-fpm/tmp
env[TEMP] = /run/php-fpm/tmp 

[www3]
prefix = /run/php-fpm/pools/$pool
listen = /run/php-fpm/php-fpm3.sock
listen.backlog = 2048
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = static
pm.max_children = 20
pm.max_requests = 500
pm.status_path = /status
request_terminate_timeout = 600
request_slowlog_timeout = 30
slowlog = /var/log/nginx/slow.log
env[TMP] = /run/php-fpm/tmp
env[TMPDIR] = /run/php-fpm/tmp
env[TEMP] = /run/php-fpm/tmp

phpをコピーしますini
sudo cp -p /etc/php.ini /opt/php56.ini

php5.6の配置は相対的に5.4で変わりません.defaultを除きます.charset="UTF-8"これは設定が必要です
=======================
肝心なのはphp-fpmサービスをどのように構成するかです.
編集/etc/systemd/system/php-fpm 2.service
[Unit]
Description=The PHP FastCGI Process Manager @develop
After=syslog.target network.target
Before=nginx.service

[Service]
#Type=forking
Type=notify
PIDFile=/run/php-fpm/php-fpm2.pid
ExecStart=/opt/local/sbin/php-fpm -c /opt/php56.ini --fpm-config /etc/php-fpm2.conf 
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
WatchdogSec=30
Restart=always

[Install]
WantedBy=multi-user.target

上のPIDFIleに注意して、ExecStartのパラメータが変わりました.またTypeは元のforkingでもいいですが、notifyに変更するメリットがあります.
変更/etc/nginx/nginx.confファイル
http {
    upstream php_servers{
        server unix:/run/php-fpm/php-fpm0.sock;
        server unix:/run/php-fpm/php-fpm1.sock;
       #server unix:/run/php-fpm/php-fpm2.sock ;
       #server unix:/run/php-fpm/php-fpm3.sock ;
    }
    upstream php_servers2{
        #server unix:/run/php-fpm/php-fpm0.sock;
        #server unix:/run/php-fpm/php-fpm1.sock;
        server unix:/run/php-fpm/php-fpm2.sock ;
        server unix:/run/php-fpm/php-fpm3.sock ;
    }

その後、nginxサイトの構成を変更し、テストサイトでphp_の使用を指定します.servers 2を解析として
    location ~ \.php$ {
        try_files      $uri =404;       #       Primary script unknown
        access_log      off;
        log_not_found   off;
       #fastcgi_pass        php_servers;
        fastcgi_pass        php_servers2;
        include             fastcgi.conf;
    }

サービスの再起動
sudo systemctl daemon-reload
sudo systemctl start php-fpm2
sudo systemctl reload nginx

これで複数バージョンのPHPが同時に走り出した.
php-fpm 2を見てください.サービスの状態は?
$ sudo systemctl status php-fpm2
php-fpm2.service - The PHP FastCGI Process Manager -develop
   Loaded: loaded (/etc/systemd/system/php-fpm2.service; enabled)
   Active: active (running) since Thu 2015-09-24 16:19:08 CST; 1 day 4h ago
 Main PID: 21928 (php-fpm)
   Status: "Processes active: 1, idle: 39, Requests: 197553, slow: 0, Traffic: 17.2req/sec"
   CGroup: /system.slice/php-fpm2.service
           ├─ 2841 php-fpm: pool www3
           ├─ 2845 php-fpm: pool www3
           ├─ 2846 php-fpm: pool www2
           ├─ 2847 php-fpm: pool www3

この行を見ましたか.
Status: "Processes active: 1, idle: 39, Requests: 197553, slow: 0, Traffic: 17.2req/sec"
これがnotifyタイプの特徴で、リアルタイム統計データを提供することができます.
仕事が终わったら、ちょうど文字数が~を超えない.
現在9998文字を入力しており、2文字を入力することもできます.