PHPを7.2から7.4へ入れ替えてみた

2021年1月31日 0 投稿者: ぱる☆ミ

WordPressのヘルスチェック項目で、PHPのバージョンが古いと怒られた。CentOS6から8へやっとサーバ移行したばかりだというのに・・・

# dnf module list php
CentOS Linux 8 - AppStream
Name                         Stream                             Profiles                                           Summary                                      
php                          7.2 [d][e]                         common [d], devel, minimal                         PHP scripting language                       
php                          7.3                                common [d], devel, minimal                         PHP scripting language                       
php                          7.4                                common [d], devel, minimal                         PHP scripting language 

あら・・・デフォルトの7.2のままだったorz

remiとか使わずに7.4をインストールできるのなら最初から入れておけば良かったけれど、気づいていなかったんだなぁ

といってもdnfかつ標準リポジトリしか使っていないのでこのような時の対応は非常に簡単。

# dnf module install php:7.4
Dependencies resolved.
The operation would result in switching of module 'php' stream '7.2' to stream '7.4'
Error: It is not possible to switch enabled streams of a module.
It is recommended to remove all installed content from the module, and reset the module using 'dnf module reset <module_name>' command. After you reset the module, you can install the other stream.

あ、怒られた。最初にphpモジュールを削除しておかないとダメなのね

# dnf module remove php
Unable to match profile in argument php
Dependencies resolved.
Nothing to do.
Complete!
# dnf module reset php
Dependencies resolved.
================================================================================================================================================================
 Package                               Architecture                         Version                                 Repository                             Size
================================================================================================================================================================
Resetting modules:
 php                                                                                                                                                           

Transaction Summary
================================================================================================================================================================

Is this ok [y/N]: y
Complete!

2コマンドで古いモジュールの削除完了、いい時代だ!

# dnf module install php:7.4
Dependencies resolved.
================================================================================================================================================================
 Package                           Architecture                Version                                                     Repository                      Size
================================================================================================================================================================
Upgrading:
 php                               x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                      1.5 M
 php-cli                           x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                      3.1 M
 php-common                        x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                      696 k
 php-fpm                           x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                      1.6 M
 php-gd                            x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                       85 k
 php-json                          x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                       74 k
 php-mbstring                      x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                      484 k
 php-mysqlnd                       x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                      192 k
 php-pdo                           x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                      123 k
 php-pecl-zip                      x86_64                      1.18.2-1.module_el8.3.0+396+9a0d79d6                        appstream                       55 k
 php-xml                           x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                      174 k
Installing dependencies:
 oniguruma                         x86_64                      6.8.2-2.el8                                                 appstream                      187 k
Installing weak dependencies:
 php-opcache                       x86_64                      7.4.6-4.module_el8.3.0+434+2ab5050a                         appstream                      267 k
Installing module profiles:
 php/common                                                                                                                                                    
Enabling module streams:
 php                                                           7.4                                                                                             

Transaction Summary
================================================================================================================================================================
Install   2 Packages
Upgrade  11 Packages

Total download size: 8.5 M
Is this ok [y/N]: y


(省略)


Upgraded:
  php-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                                 php-cli-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                             
  php-common-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                          php-fpm-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                             
  php-gd-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                              php-json-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                            
  php-mbstring-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                        php-mysqlnd-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                         
  php-pdo-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                             php-pecl-zip-1.18.2-1.module_el8.3.0+396+9a0d79d6.x86_64                       
  php-xml-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                            

Installed:
  oniguruma-6.8.2-2.el8.x86_64                                      php-opcache-7.4.6-4.module_el8.3.0+434+2ab5050a.x86_64                                     

Complete!

php7.4だけをdnfでインストールしましたが、7.2の細かいモジュールも全て自動的にアップグレードされました。

念のために # systemctl restart php-fpm だけ実行しておいて、Wordpressのヘルスチェックも問題が解消されました。もちろんコンテンツの表示も問題なし!