とりあえず無効にする。
# getenforce Enforcing
# vi /etc/sysconfig/selinux SELINUX=enforcing ↓変更 #SELINUX=enforcing SELINUX=disabled
# reboot now
ローカルなのでこっちも無効にする。
# systemctl stop firewalld
Remi レポジトリのインストール
# yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# yum install yum-utils
# yum-config-manager --enable remi
PHP のインストール
PHP53系を入れたい場合はCentOS6にするか、ソースから入れよう。
# for v in 54 55 56 70 71 ; do yum -y install php$v php$v-php-{gd,xml,mbstring,mysqlnd} ; done
# for v in 54 55 ; do yum -y install php$v-php-pecl-{apc,memcached} ; done
# for v in 56 70 71 ; do yum -y install php$v-php-{opcache,pecl-apcu,pecl-memcached} ; done
バージョンの確認
# for v in 54 55 56 70 71 ; do php$v -v ; echo \ ; done PHP 5.4.45 (cli) (built: Sep 19 2016 14:59:54) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies PHP 5.5.38 (cli) (built: Dec 10 2016 19:05:15) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies PHP 5.6.30 (cli) (built: Jan 19 2017 07:08:58) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies PHP 7.0.15 (cli) (built: Jan 17 2017 16:07:55) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.15, Copyright (c) 1999-2017, by Zend Technologies PHP 7.1.1 (cli) (built: Jan 18 2017 11:31:59) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.1.1, Copyright (c) 1999-2017, by Zend Technologies
php.ini の配置場所
# for v in 54 55 56 70 71 ; do php$v --ini | grep Loaded | awk '{print $4}' ; done /opt/remi/php54/root/etc/php.ini /opt/remi/php55/root/etc/php.ini /opt/remi/php56/root/etc/php.ini /etc/opt/remi/php70/php.ini /etc/opt/remi/php71/php.ini
# module load php54
-bash: module: コマンドが見つかりません
# source /etc/profile.d/modules.sh
# module load php54
# php -v Output PHP 5.4.45 (cli) (built: Jun 23 2016 15:01:51) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
# module unload php54
# php -v -bash: php: コマンドが見つかりません
php-fpm のインストール
# for v in 54 55 56 70 71 ; do yum -y install php$v-php-fpm ; done
PHP-FPM の設定
プロセスマネージャーの変更
# for v in 54 55 56 ; do sed -i '/pm = /s/dynamic/ondemand/' /opt/remi/php$v/root/etc/php-fpm.d/www.conf ; done
# for v in 70 71 ; do sed -i '/pm = /s/dynamic/ondemand/' /etc/opt/remi/php$v/php-fpm.d/www.conf ; done
確認
# for v in 54 55 56 ; do grep 'pm = ondemand' /opt/remi/php$v/root/etc/php-fpm.d/www.conf ; done pm = ondemand pm = ondemand pm = ondemand
# for v in 70 71 ; do grep 'pm = ondemand' /etc/opt/remi/php$v/php-fpm.d/www.conf ; done pm = ondemand pm = ondemand
[root@localhost bin]# cd /opt/remi/
[root@localhost remi]# ls -lah 合計 0 drwxr-xr-x. 7 root root 71 1月 30 22:46 . drwxr-xr-x. 4 root root 28 1月 30 22:44 .. dr-xr-xr-x. 3 root root 32 1月 30 22:44 php54 dr-xr-xr-x. 3 root root 32 1月 30 22:44 php55 dr-xr-xr-x. 3 root root 32 1月 30 22:45 php56 dr-xr-xr-x. 3 root root 32 1月 30 22:46 php70 dr-xr-xr-x. 3 root root 32 1月 30 22:46 php71
listen のポート指定
# for v in 54 55 56 ; do sed -i "s/9000/90$v/" /opt/remi/php$v/root/etc/php-fpm.d/www.conf ; done
# for v in 70 71 ; do sed -i "s/9000/90$v/" /etc/opt/remi/php$v/php-fpm.d/www.conf ; done
確認
# for v in 54 55 56 ; do grep 'listen = 127' /opt/remi/php$v/root/etc/php-fpm.d/www.conf ; done listen = 127.0.0.1:9054 listen = 127.0.0.1:9055 listen = 127.0.0.1:9056
# for v in 70 71 ; do grep 'listen = 127' /etc/opt/remi/php$v/php-fpm.d/www.conf ; done listen = 127.0.0.1:9070 listen = 127.0.0.1:9071
Apache の設定
# yum install httpd httpd-devel
# vi /etc/httpd/conf.d/remi.conf <VirtualHost *:80> ServerName php71 <FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9071" </FilesMatch> </VirtualHost> <VirtualHost *:80> ServerName php70 <FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9070" </FilesMatch> </VirtualHost> <VirtualHost *:80> ServerName php56 <FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9056" </FilesMatch> </VirtualHost> <VirtualHost *:80> ServerName php55 <FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9055" </FilesMatch> </VirtualHost> <VirtualHost *:80> ServerName php54 <FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9054" </FilesMatch> </VirtualHost>
# vi /etc/httpd/conf/httpd.conf 163行目付近 <IfModule dir_module> DirectoryIndex index.html </IfModule> ↓変更 <IfModule dir_module> DirectoryIndex index.php index.html </IfModule>
php-fpm の起動
# for v in 54 55 56 70 71 ; do systemctl start php$v-php-fpm ; systemctl enable php$v-php-fpm ; done
# systemctl start httpd && systemctl enable httpd
サンプルファイルの作成
# echo "PHP Version: <?php echo phpversion();" > /var/www/html/index.php
\Windows\System32\drivers\etc\hosts
192.168.11.35 php71 php70 php56 php55 php54
http://php71/
http://php70/
http://php56/
http://php55/
http://php54/
他に.htaccessで切り替える方法もあるけれど、Apache, Nginxとミドルウェアを選ばないのでPHP-FPMで制御するこっちの方が良いかな~(ㆁᴗㆁ✿)
@see http://qiita.com/bezeklik/items/860ba080bf4c664cd8e9