3
1

More than 1 year has passed since last update.

CentOSにおけるPHPのバージョンアップ方法(7.0→7.4)

Last updated at Posted at 2022-10-05

概要

WordPress のバージョンを 4.9 から 6.0 に引き上げた際に PHP のバージョンも 7.0 から 7.4 へ引き上げる必要があったため、その内容を備忘録としてを残します。

環境

nginx : 1.12.2
PHP : 7.0.27 (引き上げ前)→7.4.30(引き上げ後)
CentOS : 7.4.1708

内容

まずは yum コマンドを使って PHP7.4 の remi リポジトリをインストールします。

$ yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

次に必要な PHP バージョンに対応する remi リポジトリがインストールされたことを確認します。

$ ls -l /etc/yum.repos.d/

一覧の中に「remi-php74.repo」があればインストールできています。

次にインストールしたリポジトリの中から 新しいバージョンの PHP を動作させるために必要なモジュールをインストールするのですが、その前に古いバージョンの PHP モジュールを削除します。
また、これ以降の手順が上手くいかなかった時のためにインストール済みのモジュールを確認してメモに取っておくことをお勧めします。

ちなみに私の場合は以下のような内容でした。

$ yum list installed | grep php
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
php.x86_64                         7.0.27-1.el7.remi          @remi-php70       
php-cli.x86_64                     7.0.27-1.el7.remi          @remi-php70       
php-common.x86_64                  7.0.27-1.el7.remi          @remi-php70       
php-fedora-autoloader.noarch       1.0.0-1.el7                @epel             
php-fpm.x86_64                     7.0.27-1.el7.remi          @remi-php70       
php-json.x86_64                    7.0.27-1.el7.remi          @remi-php70       
php-mbstring.x86_64                7.0.27-1.el7.remi          @remi-php70       
php-mcrypt.x86_64                  7.0.27-1.el7.remi          @remi-php70       
php-mysqlnd.x86_64                 7.0.27-1.el7.remi          @remi-php70       
php-pdo.x86_64                     7.0.27-1.el7.remi          @remi-php70       
php-pear.noarch                    1:1.10.5-4.el7.remi        @remi-php70       
php-process.x86_64                 7.0.27-1.el7.remi          @remi-php70       
php-xml.x86_64                     7.0.27-1.el7.remi          @remi-php70       
php70-php-common.x86_64            7.0.27-1.el7.remi          @remi             
php70-php-fpm.x86_64               7.0.27-1.el7.remi          @remi             
php70-php-gd.x86_64                7.0.27-1.el7.remi          @remi             
php70-php-json.x86_64              7.0.27-1.el7.remi          @remi             
php70-php-mbstring.x86_64          7.0.27-1.el7.remi          @remi             
php70-php-mcrypt.x86_64            7.0.27-1.el7.remi          @remi             
php70-php-mysqlnd.x86_64           7.0.27-1.el7.remi          @remi             
php70-php-pdo.x86_64               7.0.27-1.el7.remi          @remi             
php70-php-pecl-mysql.x86_64        1.0.0-0.9.20151007git294ce3b.el7.remi
php70-runtime.x86_64               1.0-5.el7.remi             @remi     

確認が取れたら、これらのモジュールを削除します。

$ yum remove php*

次に PHP7.4 のモジュールを有効化します。

$ yum info --enablerepo=remi,remi-php74 php

そして PHP7.4 の必要なモジュールをインストールします。

$ yum install --enablerepo=remi,remi-php74 php php-devel php-gd など

インストールが終われば、必要なモジュールが入っていることを確認します。

$ yum list installed | grep php
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
gd3php.x86_64                      2.3.3-7.el7.remi           @remi             
oniguruma5php.x86_64               6.9.8-1.el7.remi           @remi             
php.x86_64                         7.4.30-1.el7.remi          @remi-php74       
php-cli.x86_64                     7.4.30-1.el7.remi          @remi-php74       
php-common.x86_64                  7.4.30-1.el7.remi          @remi-php74       
php-fpm.x86_64                     7.4.30-1.el7.remi          @remi-php74       
php-gd.x86_64                      7.4.30-1.el7.remi          @remi-php74       
php-imap.x86_64                    7.4.30-1.el7.remi          @remi-php74       
php-json.x86_64                    7.4.30-1.el7.remi          @remi-php74       
php-mbstring.x86_64                7.4.30-1.el7.remi          @remi-php74       
php-mysqlnd.x86_64                 7.4.30-1.el7.remi          @remi-php74       
php-odbc.x86_64                    7.4.30-1.el7.remi          @remi-php74       
php-opcache.x86_64                 7.4.30-1.el7.remi          @remi-php74       
php-pdo.x86_64                     7.4.30-1.el7.remi          @remi-php74       
php-pear.noarch                    1:1.10.13-1.el7.remi       @remi             
php-pecl-apcu.x86_64               5.1.21-1.el7.remi.7.4      @remi-php74       
php-pecl-mcrypt.x86_64             1.0.5-1.el7.remi.7.4       @remi-php74       
php-pgsql.x86_64                   7.4.30-1.el7.remi          @remi-php74       
php-process.x86_64                 7.4.30-1.el7.remi          @remi-php74       
php-snmp.x86_64                    7.4.30-1.el7.remi          @remi-php74       
php-sodium.x86_64                  7.4.30-1.el7.remi          @remi-php74       
php-xml.x86_64                     7.4.30-1.el7.remi          @remi-php74       
php-xmlrpc.x86_64                  7.4.30-1.el7.remi          @remi-php74

確認して問題なければ php-fpm を再起動します。

$ systemctl restart php-fpm 

そしてサーバーを再起動します。

$ systemctl restart nginx

最後にバージョンを確認し、7.4 になっていれば成功です。

$ php -v
PHP 7.4.30 (cli) (built: Jun  7 2022 08:38:19) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies

参考

PHPを7.3から7.4にアップグレードする手順(CentOS 7) | 己で解決!泣かぬなら己で鳴こうホトトギス

3
1
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
3
1