開発環境のPHP7.4に8.0を+して切り替えながら使用する【1】

開発環境

この記事(【PHP8.0】PHPに名前付き引数が実装される)を読んだだけで、もうこれはやるしかない!!と。

そういうわけで、ほぼワードプレスのテスト運用だけが目的のローカルサーバーでPHP8.0にアップグレードして遊ぶ記事です。
この記事ではPHP8.0のインストールと7.4との間の切り替えまでやりますが、完結していません。
次の【2】で、
・Apache2で読み込むモジュールを切り替える
・PHP8.0への切り替え後発生した不具合への対応
このあたりを記事にする予定です。


まずは、PHP 7.4.x から PHP 8.0.x への移行ここは激しくチェック。特に「下位互換のない変更点」とか。

というわけで、Virtual Box 上のVagrantに構築したUbuntu20.04のLAMP環境(PHP7.4)にPHP8.0を追加インストールし、切り替えながら使えるようにします。
というか、マズかったらすぐに7.4に戻すため、ということですね。

ちなみに、あくまでもワードプレスさえ動けば良い、というものなので、そこに目標を置いて作業を進めます。

ワードプレスの対応状況

2021年3月中旬現在の状況ですが、ワードプレスは5.6からPHP8に対応しているようです。ただし、今回はPHPのメジャーバージョンアップであり変更点が非常に多いため、

it is very likely that there are still undiscovered issues remaining.

未知の問題はまだ残っているであろう、という段階だということですね。
それより何より重要なことは、

WordPress is never used in isolation (without any theme or plugins), so WordPress itself being able to run on PHP 8 does not indicate “full” compatibility.

つまり、ワードプレスってのはプラグインやテーマを使わず「WordPressのみを単独利用する」ってことがほぼ無いので、ワードプレスがPHP8に対応したということが即ち「ワードプレスがPHP8に"完全に"対応した(完全互換になった)」とは言えない、ということを理解しておかねばなりませぬ。

現在のローカル環境の状況

Virtual Box / Vagrant / Ubuntu について

# Virtual Boxのバージョン
$ VBoxManage -v
6.0.10r132072

# Vagrantのバージョン確認
$ vagrant version
==> vagrant: A new version of Vagrant is available: 2.2.14 (installed version: 2.2.5)!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html

Installed Version: 2.2.5
Latest Version: 2.2.14

ゲストマシンに入って

# Ubuntuのバージョン
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

# これでもいい
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:    20.04
Codename:   focal

PHPやモジュールなど

# phpのバージョンをチェック
$ php -v
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

php関連のパッケージ・モジュールを確認して、ファイルに書き出しておく(何かあった際に比較確認できるようにするため)。

# 一連の作業用のフォルダを作って、移動しておく。 
$ mkdir ~/php-upgrade && cd ~/php-upgrade

# インストールされているPHP関連パッケージを確認して、ファイルに書き出しておく。
$ apt list --installed | grep php > php74-packages.txt
# 見る。
$ cat php74-packages.txt 
libapache2-mod-php7.4/focal-updates,focal-security,now 7.4.3-4ubuntu2.4 amd64 [installed]
php-cli/focal,focal,now 2:7.4+75 all [installed]
php-common/focal,focal,now 2:75 all [installed]

〜 中略 〜

php-xmlrpc/focal,focal,now 2:7.4+75 all [installed]
php-zip/focal,focal,now 2:7.4+75 all [installed]
php7.4-cli/focal-updates,focal-security,now 7.4.3-4ubuntu2.4 amd64 [installed,automatic]
php7.4-common/focal-updates,focal-security,now 7.4.3-4ubuntu2.4 amd64 [installed,automatic]

〜 中略 〜

php7.4-xmlrpc/focal-updates,focal-security,now 7.4.3-4ubuntu2.4 amd64 [installed,automatic]
php7.4-zip/focal-updates,focal-security,now 7.4.3-4ubuntu2.4 amd64 [installed,automatic]
php/focal,focal,now 2:7.4+75 all [installed]

# モジュールについても同様に。
$ php -m > php74-modules.txt
# 見る
$ cat php74-modules.txt 
[PHP Modules]
calendar
Core
ctype

〜 中略 〜

Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

# php.iniのバックアップも取っておく
$ php -i | grep php.ini
Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini

$ cp /etc/php/7.4/cli/php.ini php.ini_74

# Apacheモジュール版の場合は以下
/etc/php/7.4/apache2/php.ini

ワードプレス

ワードプレスのバージョン:5.7
使用テーマ:Luxeritas

テーマのバージョンはテーマフォルダ中のstyle.cssに記述がある。

・親テーマ

 *   Theme Name: Luxeritas
 *   Theme URI: https://thk.kanzae.net/wp/
 *   Description: SEO optimized, Responsive layout, Super Fast, Multi Feature, Bootstrap

〜 中略 〜   

 *   Text Domain: luxeritas
 *   Since: 20151206
 *   Modify: 20201218
 *   Version: 3.12.0.1

・子テーマ

 *   Theme Name: Luxeritas Child Theme
 *   Template: luxeritas
 *   Text Domain: luxech
 *   Theme URI: http://thk.kanzae.net/wp/

〜 中略 〜

 *   Since: 20151206
 *   Modify: 20200401
 *   Version: 3.0.3
 *   Template Version: 3

親テーマが2020年12月18日にアップデートされていますが、子テーマは同年4月が最新。まあ子テーマにPHPのコードがあるとすれば自分で記述したものでしょうから、自分でちゃんと手入れしましょう。

開発者さんのブログ
ブログの方ではPHP8についての言及は特にないので、確認してみることにします。

PHP8.0のインストール

準備

PPAについてはここを参照:

# PPAを追加する
$ sudo add-apt-repository ppa:ondrej/php
 Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided.

Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa

You can get more information about the packages at https://deb.sury.org

IMPORTANT: The <foo>-backports is now required on older Ubuntu releases.

BUGS&FEATURES: This PPA now has a issue tracker:
https://deb.sury.org/#bug-reporting

CAVEATS:
1. If you are using php-gearman, you need to add ppa:ondrej/pkg-gearman
2. If you are using apache2, you are advised to add ppa:ondrej/apache2
3. If you are using nginx, you are advised to add ppa:ondrej/nginx-mainline
   or ppa:ondrej/nginx

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/

WARNING: add-apt-repository is broken with non-UTF-8 locales, see
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
 More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Press [ENTER] to continue or Ctrl-c to cancel adding it.

Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease                                       
Get:5 http://ppa.launchpad.net/ondrej/php/ubuntu focal InRelease [23.9 kB]                             
Get:6 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 Packages [91.1 kB]                   
Get:7 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main i386 Packages [29.7 kB]                                                                                                                        
Get:8 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main Translation-en [31.2 kB]                                                                                                                       
Fetched 176 kB in 15s (11.7 kB/s)                                                                                                                                                                          
Reading package lists... Done

# パッケージ一覧の更新
$ sudo apt update

# インストール可能なphpのバージョンをチェック
$ sudo apt search php | grep php
長いので省略(笑) 8.0まであることは分かった。

PHP本体のインストール

# とりあえずPHP本体をインストールしよう
$ sudo apt -y install php8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  ieee-data python3-argcomplete python3-crypto python3-distutils python3-dnspython python3-httplib2 python3-jinja2 python3-jmespath python3-kerberos python3-lib2to3 python3-libcloud python3-lockfile
  python3-markupsafe python3-netaddr python3-ntlm-auth python3-requests-kerberos python3-requests-ntlm python3-selinux python3-simplejson python3-winrm python3-xmltodict
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libapache2-mod-php8.0 php8.0-cli php8.0-common php8.0-opcache php8.0-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libapache2-mod-php8.0 php8.0 php8.0-cli php8.0-common php8.0-opcache php8.0-readline
0 upgraded, 6 newly installed, 0 to remove and 74 not upgraded.
Need to get 4,407 kB of archives.
After this operation, 20.0 MB of additional disk space will be used.
Get:1 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-common amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [1,039 kB]
Get:2 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-opcache amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [456 kB]                                                                       
Get:3 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-readline amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [12.6 kB]                                                                     
Get:4 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-cli amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [1,468 kB]                                                                         
Get:5 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 libapache2-mod-php8.0 amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [1,406 kB]                                                              
Get:6 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0 all 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [24.3 kB]                                                                                
Fetched 4,407 kB in 37s (119 kB/s)                                                                                                                                                                         
Selecting previously unselected package php8.0-common.
(Reading database ... 117577 files and directories currently installed.)
Preparing to unpack .../0-php8.0-common_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-common (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0-opcache.
Preparing to unpack .../1-php8.0-opcache_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-opcache (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0-readline.
Preparing to unpack .../2-php8.0-readline_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-readline (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0-cli.
Preparing to unpack .../3-php8.0-cli_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-cli (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package libapache2-mod-php8.0.
Preparing to unpack .../4-libapache2-mod-php8.0_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking libapache2-mod-php8.0 (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0.
Preparing to unpack .../5-php8.0_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_all.deb ...
Unpacking php8.0 (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Setting up php8.0-common (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/mods-available/calendar.ini with new version

Creating config file /etc/php/8.0/mods-available/ctype.ini with new version

Creating config file /etc/php/8.0/mods-available/exif.ini with new version

Creating config file /etc/php/8.0/mods-available/fileinfo.ini with new version

Creating config file /etc/php/8.0/mods-available/ffi.ini with new version

Creating config file /etc/php/8.0/mods-available/ftp.ini with new version

Creating config file /etc/php/8.0/mods-available/gettext.ini with new version

Creating config file /etc/php/8.0/mods-available/iconv.ini with new version

Creating config file /etc/php/8.0/mods-available/pdo.ini with new version

Creating config file /etc/php/8.0/mods-available/phar.ini with new version

Creating config file /etc/php/8.0/mods-available/posix.ini with new version

Creating config file /etc/php/8.0/mods-available/shmop.ini with new version

Creating config file /etc/php/8.0/mods-available/sockets.ini with new version

Creating config file /etc/php/8.0/mods-available/sysvmsg.ini with new version

Creating config file /etc/php/8.0/mods-available/sysvsem.ini with new version

Creating config file /etc/php/8.0/mods-available/sysvshm.ini with new version

Creating config file /etc/php/8.0/mods-available/tokenizer.ini with new version
Setting up php8.0-readline (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/mods-available/readline.ini with new version
Setting up php8.0-opcache (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/mods-available/opcache.ini with new version
Setting up php8.0-cli (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
update-alternatives: using /usr/bin/php8.0 to provide /usr/bin/php (php) in auto mode
update-alternatives: using /usr/bin/phar8.0 to provide /usr/bin/phar (phar) in auto mode
update-alternatives: using /usr/bin/phar.phar8.0 to provide /usr/bin/phar.phar (phar.phar) in auto mode

Creating config file /etc/php/8.0/cli/php.ini with new version
Setting up libapache2-mod-php8.0 (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/apache2/php.ini with new version
libapache2-mod-php8.0: php7.4 module already enabled, not enabling PHP 8.0
Setting up php8.0 (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for php8.0-cli (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for libapache2-mod-php8.0 (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

自動的に追加されるパッケージ

ieee-data
python3-argcomplete
python3-crypto
python3-distutils
python3-dnspython
python3-httplib2
python3-jinja2
python3-jmespath
python3-kerberos
python3-lib2to3
python3-libcloud
python3-lockfile
python3-markupsafe
python3-netaddr
python3-ntlm-auth
python3-requests-kerberos
python3-requests-ntlm
python3-selinux
python3-simplejson
python3-winrm
python3-xmltodict
libapache2-mod-php8.0
php8.0-cli
php8.0-common
php8.0-opcache
php8.0-readline

Suggested packages:
php-pear # suggestってことは自分で入れたらいいのか?

php-commonから入ってくるモジュールは

calendar.ini
ctype.ini
exif.ini
fileinfo.ini
ffi.ini
ftp.ini
gettext.ini
iconv.ini
pdo.ini
phar.ini
posix.ini
shmop.ini
sockets.ini
sysvmsg.ini
sysvsem.ini
sysvshm.ini
tokenizer.ini

これぐらいかな?

さて、これでPHPのバージョンを確認すると、もう8.0が有効になっていることが分かります。

$ php -v
PHP 8.0.3 (cli) (built: Mar  5 2021 07:54:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.3, Copyright (c), by Zend Technologies

関連パッケージのインストール

とりあえず、パッケージの確認。

$ sudo apt search php8.0-*

たくさん出てきますので、必要なものだけ入れましょう。
この一覧からだと、こんなもんでしょうか。いくつか足りないものがあるような気もしますが、とりあえず入れましょう。

$ sudo apt -y install php8.0-curl php8.0-fpm php8.0-gd php8.0-mbstring php8.0-mcrypt php8.0-mysql php8.0-xml
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  ieee-data python3-argcomplete python3-crypto python3-distutils python3-dnspython python3-httplib2 python3-jinja2 python3-jmespath python3-kerberos python3-lib2to3 python3-libcloud python3-lockfile
  python3-markupsafe python3-netaddr python3-ntlm-auth python3-requests-kerberos python3-requests-ntlm python3-selinux python3-simplejson python3-winrm python3-xmltodict
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libmcrypt4
Suggested packages:
  libmcrypt-dev mcrypt php-pear
The following NEW packages will be installed:
  libmcrypt4 php8.0-curl php8.0-fpm php8.0-gd php8.0-mbstring php8.0-mcrypt php8.0-mysql php8.0-xml
0 upgraded, 8 newly installed, 0 to remove and 74 not upgraded.
Need to get 2,233 kB of archives.
After this operation, 7,609 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 libmcrypt4 amd64 2.5.8-3.4 [64.6 kB]
Get:2 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-mcrypt amd64 3:1.0.4-5+ubuntu20.04.1+deb.sury.org+1 [16.2 kB]                                                                     
Get:3 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-curl amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [33.0 kB]                                                                         
Get:4 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-fpm amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [1,477 kB]                                                                         
Get:5 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-gd amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [27.6 kB]                                                                           
Get:6 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-mbstring amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [395 kB]                                                                      
Get:7 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-mysql amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [121 kB]                                                                         
Get:8 http://ppa.launchpad.net/ondrej/php/ubuntu focal/main amd64 php8.0-xml amd64 8.0.3-1+ubuntu20.04.1+deb.sury.org+1 [98.4 kB]                                                                          
Fetched 2,233 kB in 1min 20s (27.9 kB/s)                                                                                                                                                                   
Selecting previously unselected package libmcrypt4.
(Reading database ... 117687 files and directories currently installed.)
Preparing to unpack .../0-libmcrypt4_2.5.8-3.4_amd64.deb ...
Unpacking libmcrypt4 (2.5.8-3.4) ...
Selecting previously unselected package php8.0-mcrypt.
Preparing to unpack .../1-php8.0-mcrypt_3%3a1.0.4-5+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-mcrypt (3:1.0.4-5+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0-curl.
Preparing to unpack .../2-php8.0-curl_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-curl (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0-fpm.
Preparing to unpack .../3-php8.0-fpm_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-fpm (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0-gd.
Preparing to unpack .../4-php8.0-gd_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-gd (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0-mbstring.
Preparing to unpack .../5-php8.0-mbstring_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-mbstring (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0-mysql.
Preparing to unpack .../6-php8.0-mysql_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-mysql (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Selecting previously unselected package php8.0-xml.
Preparing to unpack .../7-php8.0-xml_8.0.3-1+ubuntu20.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.0-xml (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Setting up php8.0-xml (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/mods-available/dom.ini with new version

Creating config file /etc/php/8.0/mods-available/simplexml.ini with new version

Creating config file /etc/php/8.0/mods-available/xml.ini with new version

Creating config file /etc/php/8.0/mods-available/xmlreader.ini with new version

Creating config file /etc/php/8.0/mods-available/xmlwriter.ini with new version

Creating config file /etc/php/8.0/mods-available/xsl.ini with new version
Setting up php8.0-mysql (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/mods-available/mysqlnd.ini with new version

Creating config file /etc/php/8.0/mods-available/mysqli.ini with new version

Creating config file /etc/php/8.0/mods-available/pdo_mysql.ini with new version
Setting up php8.0-mbstring (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/mods-available/mbstring.ini with new version
Setting up php8.0-gd (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/mods-available/gd.ini with new version
Setting up php8.0-fpm (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/fpm/php.ini with new version
NOTICE: Not enabling PHP 8.0 FPM by default.
NOTICE: To enable PHP 8.0 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php8.0-fpm
NOTICE: You are seeing this message because you have apache2 package installed.
Created symlink /etc/systemd/system/multi-user.target.wants/php8.0-fpm.service → /lib/systemd/system/php8.0-fpm.service.
Setting up php8.0-curl (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...

Creating config file /etc/php/8.0/mods-available/curl.ini with new version
Setting up libmcrypt4 (2.5.8-3.4) ...
Setting up php8.0-mcrypt (3:1.0.4-5+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Processing triggers for systemd (245.4-4ubuntu3.4) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libapache2-mod-php8.0 (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for php8.0-cli (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
Processing triggers for php8.0-fpm (8.0.3-1+ubuntu20.04.1+deb.sury.org+1) ...
NOTICE: Not enabling PHP 8.0 FPM by default.
NOTICE: To enable PHP 8.0 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php8.0-fpm
NOTICE: You are seeing this message because you have apache2 package installed.

NOTICEが出てるのはFPMはインストールしてるだけで有効になってねーからな、有効にするにはこうしなさいよ、と言ってるだけです。何故か同じことを二回言われていますな。
あと、いくつか追加パッケージをrecommendしてきているので素直に入れておこうと思います。

$ sudo apt install -y libmcrypt-dev mcrypt php-pear

# ついでにlibmash2ってのもインストールされるようです。
The following additional packages will be installed:
  libmhash2

いざ、確認

この環境で、いよいよワードプレスを立ち上げてみます。

実は、この記事を書きながら(ローカル環境で執筆しています)、まさにこの環境でPHPを8.0にアップグレードしていたのですが、あっさり問題なく立ち上がってしまいました。

プラグインはマークダウン記法を使えるようにするために
・WP Githuber MD
これを入れているだけなので(だからこそこの環境で試したのですw)、プラグインを多数入れている環境だとどうなるかわかりません。

また、Luxeritasテーマも全く問題なしです。

PHPのバージョンを切り替える

さて、これでPHP7.4が入っていた環境に8.0を追加して、自動的に8.0が適用されている状態になったわけですが、7.4に戻したい場合、あるいはさらにそれから8.0に戻したい場合についてです。

$ sudo update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.0   80        auto mode
  1            /usr/bin/php7.4   74        manual mode
  2            /usr/bin/php8.0   80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 

番号を入れて選べ!というわけで、「1」の7.4を選択してみます。

Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/php7.4 to provide /usr/bin/php (php) in manual mode

$ php -v
PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

再び8.0へ

$ sudo update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
  0            /usr/bin/php8.0   80        auto mode
* 1            /usr/bin/php7.4   74        manual mode
  2            /usr/bin/php8.0   80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/php8.0 to provide /usr/bin/php (php) in manual mode

$ php -v
PHP 8.0.3 (cli) (built: Mar  5 2021 07:54:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.3, Copyright (c), by Zend Technologies

はい、めでたしめでたし・・・

とはいかないのです。

OS上はPHPの切り替えができていますが、実は肝心のWEBサーバー、我らがApacheさんはそんなことつゆ知らず、PHP7.4を読み込み、使い続けておりました。そりゃあ異常ないわけだわ。

phpinfoを使って確認するとよく分かると思います。

これを解決するのは次の記事にて!