以前、Apache2.4の環境でPHP7.0からPHP7.2へアップグレードする方法について紹介しました。
NginxをPHPで使用すると、PHP-FPMを使用しますが、PHP7.0からPHP7.2へのアップデートの方法はApacheを使用している場合とNginxを使用している場合は若干の違いがあるので記事にします。
環境
バージョン
- CentOS 7
- PHP 7.2.7
- MySQL 5.7.22
- Nginx 1.12.2
現状把握
インストールされているPHPのバージョンを確認します。
php -v PHP 7.0.31 (cli) (built: Jul 17 2018 15:30:29) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
インストールされているRPMパッケージの状態を確認しておきます。
[vagrant@localhost log]$ rpm -qa | grep php php-json-7.0.31-1.el7.remi.x86_64 php-7.0.31-1.el7.remi.x86_64 php-gd-7.0.31-1.el7.remi.x86_64 php-pecl-apcu-5.1.12-1.el7.remi.7.0.x86_64 php-common-7.0.31-1.el7.remi.x86_64 php-cli-7.0.31-1.el7.remi.x86_64 php-pdo-7.0.31-1.el7.remi.x86_64 php-mbstring-7.0.31-1.el7.remi.x86_64 php-xml-7.0.31-1.el7.remi.x86_64 php-fpm-7.0.31-1.el7.remi.x86_64 php-process-7.0.31-1.el7.remi.x86_64 php-pear-1.10.5-6.el7.remi.noarch php-pecl-zip-1.15.3-1.el7.remi.7.0.x86_64 php-mysqlnd-7.0.31-1.el7.remi.x86_64 php-xmlrpc-7.0.31-1.el7.remi.x86_64 php-fedora-autoloader-1.0.0-1.el7.remi.noarch
PHP7.0.30のバージョンが入っていることが確認できます。
次に、導入しているremiリポジトリに7.2があるか確認します。
[vagrant@localhost log]$ ll /etc/yum.repos.d/ | grep remi- -rw-r--r--. 1 root root 446 6月 19 08:28 remi-glpi91.repo -rw-r--r--. 1 root root 446 6月 19 08:28 remi-glpi92.repo -rw-r--r--. 1 root root 446 6月 19 08:28 remi-glpi93.repo -rw-r--r--. 1 root root 456 6月 19 08:28 remi-php54.repo -rw-r--r--. 1 root root 1314 6月 19 08:28 remi-php70.repo -rw-r--r--. 1 root root 1314 6月 19 08:28 remi-php71.repo -rw-r--r--. 1 root root 1314 6月 19 08:28 remi-php72.repo -rw-r--r--. 1 root root 1314 6月 19 08:28 remi-php73.repo -rw-r--r--. 1 root root 750 6月 19 08:28 remi-safe.repo
7.2のリポジトリが無い場合はremiリポジトリをアップデートしてください。
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
PHPの削除
現在、インストールされているPHPを削除します。
yum remove php-*
PHP 7.2のインストール
まず、導入出来るPHPの詳細を確認します
[vagrant@localhost log]$ yum info --enablerepo=remi,remi-php72 php 読み込んだプラグイン:fastestmirror remi-php72 | 2.9 kB 00:00:00 remi-php72/primary_db | 195 kB 00:00:00 Determining fastest mirrors * base: ftp.iij.ad.jp * extras: ftp.iij.ad.jp * remi: ftp.riken.jp * remi-php72: ftp.riken.jp * remi-safe: ftp.riken.jp * updates: ftp.iij.ad.jp インストール済みパッケージ 名前 : php アーキテクチャー : x86_64 バージョン : 7.0.31 リリース : 1.el7.remi 容量 : 8.2 M リポジトリー : installed 提供元リポジトリー : remi-php70 要約 : PHP scripting language for creating dynamic web sites URL : http://www.php.net/ ライセンス : PHP and Zend and BSD and MIT and ASL 1.0 説明 : PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated web pages. PHP also : offers built-in database integration for several commercial and : non-commercial database management systems, so writing a : database-enabled webpage with PHP is fairly simple. The most common : use of PHP coding is probably as a replacement for CGI scripts. : : The php package contains the module (often referred to as mod_php) : which adds support for the PHP language to Apache HTTP Server. 利用可能なパッケージ 名前 : php アーキテクチャー : x86_64 バージョン : 7.2.9 リリース : 1.el7.remi 容量 : 3.2 M リポジトリー : remi-php72 要約 : PHP scripting language for creating dynamic web sites URL : http://www.php.net/ ライセンス : PHP and Zend and BSD and MIT and ASL 1.0 and NCSA 説明 : PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated web pages. PHP also : offers built-in database integration for several commercial and : non-commercial database management systems, so writing a : database-enabled webpage with PHP is fairly simple. The most common : use of PHP coding is probably as a replacement for CGI scripts. : : The php package contains the module (often referred to as mod_php) : which adds support for the PHP language to Apache HTTP Server.
PHP7.2のインストール
yum install --enablerepo=remi,remi-php72 php
エラー: パッケージ: php-7.2.9-1.el7.remi.x86_64 (remi-php72)
要求: libargon2.so.0()(64bit)
ようなエラーが出る場合は、「epel」リポジトリをを追加してコマンドを打ってください。下記に例を示します。
yum install --enablerepo=epel,remi,remi-php72 php
PHPアップデート後のバージョンの確認
[vagrant@localhost log]$ php -v PHP 7.2.9 (cli) (built: Aug 15 2018 09:19:33) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
PHP7.2がインストールされました。
PHPの拡張機能のインストール
yum -y install --enablerepo=remi --enablerepo=remi-php72 php php-opcache php-devel php-mbstring php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-gd php-intl php-symfony php php-pdo php-xml php-tokenizer php-pear php-zip php-fpm
/etc/php-fpm.d/www.confの編集
php-fpmをアップデートし入れ替えているので、etc/php-fpm.d/www.confを編集します。
$ vi /etc/php-fpm.d/www.conf ;変更 user = nginx group = nginx ;変更と追加 listen = /var/run/php-fpm.sock listen.owner = nginx listen.group = nginx ;コメントアウト ;listen = 127.0.0.1:9000
nginxとphp-fpmの再起動
nginxの再起動
systemctl restart nginx
php-fpmの再起動
systemctl restart php-fpm
これで、Centos7 + Nginx環境のPHPを7.0から7.2にアップデートすることができました。
php-fpm以外のところは、ApacheでPHPをアップデートするのと同じ方法で行うことができます。
PHPのバージョンをあげる際には参考にして見てください。