install CentOS7+PHP7 - opensource-workshop/connect-cms GitHub Wiki
- CentOS7にphp7系を追加インストールする。
- php7系はSoftware Collectionリポジトリのphp7最新7.3を利用する。
- php(7.3)はFastCGI(php-fpm)で動作。システムのデフォルトのphp(5.4)と併用する。
- apache設定で追加インストールしたphp7を指定する。
yum install centos-release-scl scl-utils
vi /etc/yum.repos.d/CentOS-SCLo-scl.repo
enabled=1
↓
enabled=0
vi /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
enabled=1
↓
enabled=0
yum install --enablerepo=centos-sclo-rh rh-php73 rh-php73-php-devel rh-php73-php-mbstring rh-php73-php-mysqlnd rh-php73-php-xml rh-php73-php-gd rh-php73-php-bcmath rh-php73-php-fpm
php.ini-productionを/etc/php.iniにコピーして、適宜編集する。
mv /etc/opt/rh/rh-php73/php.ini /etc/opt/rh/rh-php73/php.ini.`date +\%Y\%m\%d`
cp /opt/rh/rh-php73/root/usr/share/doc/rh-php73-php-common-7.3.11/php.ini-production /etc/opt/rh/rh-php73/php.ini
chown root.wheel /etc/opt/rh/rh-php73/php.ini
chmod g+w /etc/opt/rh/rh-php73/php.ini
source scl_source enable rh-php73
php -v
PHP 7.3.11 (cli) (built: Dec 10 2019 16:14:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
php -i | grep "Loaded Configuration File"
Loaded Configuration File => /etc/opt/rh/rh-php73/php.ini
cd /opt/rh/rh-php73/root
find . -name *php.ini*
./usr/share/doc/rh-php73-php-common-7.3.11/php.ini-development
./usr/share/doc/rh-php73-php-common-7.3.11/php.ini-production
php-fpmを再起動すると、サーバに反映される
systemctl restart rh-php73-php-fpm
systemctl status rh-php73-php-fpm
systemctl enable rh-php73-php-fpm
// apache設定例
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName php73.xxxxxx
ErrorLog logs/error_log
CustomLog logs/access_log combined
# php-fpm(php7)で動作させる設定
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
</VirtualHost>
設定を反映させるために、apacheをゆるやかに再起動
apachectl configtest
apachectl graceful
これでCentOS7+PHP7の設定完了です。
- コマンドでコマンドラインのphpバージョンを7に切り替える。
source scl_source enable rh-php73
- インストール作業 をする
- コマンドでコマンドラインのphpバージョンを7に切り替える。
source scl_source enable rh-php73
- アップデート作業 をする
複数php-fpmを動かしていた時のエラー
# systemctl status rh-php73-php-fpm -l
● rh-php73-php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/rh-php73-php-fpm.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 火 2020-12-08 16:00:44 JST; 44s ago
Process: 31729 ExecStart=/opt/rh/rh-php73/root/usr/sbin/php-fpm --nodaemonize (code=exited, status=78)
Main PID: 31729 (code=exited, status=78)
12月 08 16:00:44 php73.xxxxxx systemd[1]: Starting The PHP FastCGI Process Manager...
12月 08 16:00:44 php73.xxxxxx php-fpm[31729]: [08-Dec-2020 16:00:44] ERROR: unable to bind listening socket for address '127.0.0.1:9000': Address already in use (98)
12月 08 16:00:44 php73.xxxxxx php-fpm[31729]: [08-Dec-2020 16:00:44] ERROR: FPM initialization failed
12月 08 16:00:44 php73.xxxxxx systemd[1]: rh-php73-php-fpm.service: main process exited, code=exited, status=78/n/a
12月 08 16:00:44 php73.xxxxxx systemd[1]: Failed to start The PHP FastCGI Process Manager.
12月 08 16:00:44 php73.xxxxxx systemd[1]: Unit rh-php73-php-fpm.service entered failed state.
12月 08 16:00:44 php73.xxxxxx systemd[1]: rh-php73-php-fpm.service failed.
php-fpmを2つ動かす場合は、listen のポート変更する
chown root.wheel -R /etc/opt/rh/rh-php73/
chmod g+w -R /etc/opt/rh/rh-php73/
vi /etc/opt/rh/rh-php73/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen = 127.0.0.1:9001
⇒ php-fpmを2つ動かす場合は、ここの設定を変える。
# systemctl start rh-php73-php-fpm
# systemctl status rh-php73-php-fpm
● rh-php73-php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/rh-php73-php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since 火 2020-12-08 16:05:18 JST; 1s ago
Main PID: 32281 (php-fpm)
Status: "Ready to handle connections"
CGroup: /system.slice/rh-php73-php-fpm.service
├─32281 php-fpm: master process (/etc/opt/rh/rh-php73/php-fpm.conf)
├─32282 php-fpm: pool www
├─32283 php-fpm: pool www
├─32284 php-fpm: pool www
├─32285 php-fpm: pool www
└─32286 php-fpm: pool www
12月 08 16:05:18 php73.xxxxxx systemd[1]: Starting The PHP FastCGI Process Manager...
12月 08 16:05:18 php73.xxxxxx systemd[1]: Started The PHP FastCGI Process Manager.
⇒ 動いた
yum installで除外設定の影響エラー
yum install --enablerepo=centos-sclo-rh rh-php73 rh-php73-php-devel rh-php73-php-mbstring rh-php73-php-mysqlnd rh-php73-php-xml rh-php73-php-gd rh-php73-php-bcmath rh-php73-php-fpm
エラー: パッケージ: glibc-headers-2.17-317.el7.x86_64 (base)
要求: kernel-headers >= 2.2.1
エラー: パッケージ: glibc-headers-2.17-317.el7.x86_64 (base)
要求: kernel-headers
問題を回避するために --skip-broken を用いることができます。
これらを試行できます: rpm -Va --nofiles --nodigest
// 確認
# view /etc/yum.conf
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
exclude=kern*
⇒ kernelのupdateが止められていた。
yumの除外設定をオプション指定で無効にする --disableexcludes=all
yum install --disableexcludes=all --enablerepo=centos-sclo-rh rh-php73 rh-php73-php-devel rh-php73-php-mbstring rh-php73-php-mysqlnd rh-php73-php-xml rh-php73-php-gd rh-php73-php-bcmath rh-php73-php-fpm
Software Collectionのサポート期限
・php7.3のSoftware Collectionのサポート期限は、2024年6月まで。
※ 参考 PHP7.3公式 2021/12/06まで(セキュリティサポート)
※ 参考 PHP7.2公式 2020/11/30まで(セキュリティサポート) ※既に期限切れ
※ 参考 PHP7.2ソフトウェアコレクション 2020年11月まで ※既に期限切れ
centos-release-scl-rhとcentos-release-sclの違い
http://www.tooyama.org/el7/scl.html
Software Collectionsで提供されるパッケージについて CentOSでSoftware Collectionsパッケージをインストールするには、yumコマンドで次のリポジトリーパッケージをインストールします。 CentOS向けにはRHELSC互換の各種パッケージをインストールできるcentos-release-scl-rhと、 CentOS SCLo SIGが提供するパッケージをインストールできるcentos-release-sclが用意されています。
⇒ centos-release-scl-rhで問題なし。