wordpressのサイトヘルスでPHPが旧いと怒られたのでPHPを更新した。その際の実施メモ。
まだ、エラーが残っていたので追記(3.3)と一部追記(3.2) 2025/11/20
背景
本サイトでwordpressを運用しているが、サイトヘルスでPHPの版数が旧いので更新してください、と怒られていた。そこでPHPの更新に取り組んだが、それなりに大変だったの記録として残す事にした。
なお、OSがbusterのままだとPHPを更新出来なかったのでOSもバージョンアップした。
更新前の状況
OS: Raspbian buster PHP: ver. 7.4
更新後の状況
OS: Raspberry Pi OS bullseye PHP: ver. 8.4
第一段階 raspberry Pi OSのバージョンをbusterからbullseyeに更新
1.1 ソースリストの変更
1.1.1 sources.list中のbusterをbullseyeに変更する
(security部分に一部フォーマットの変更もあり)
sudo nano /etc/apt/sources.list
下記の様になる様に変更する
deb http://deb.debian.org/debian bullseye main contrib non-free
deb http://deb.debian.org/debian-security/ bullseye-security main contrib non-free
deb http://deb.debian.org/debian bullseye-updates main contrib non-free
1.1.2 sources.list.d/raspi.list中のbusterをbullseyeに変更する
sudo nano /etc/apt/sources.list.d/raspi.list
下記の様になる様に変更する
deb http://archive.raspberrypi.org/debian/ bullseye main
1.2 OSを更新
sudo apt update
sudo apt upgrade --without-new-pkgs
sudo apt full-upgrade
sudo apt autoremove
sudo apt install zstd
(bookwormに更新時必要になるのでついでにインストールしておく)
sudo reboot
1.3 xrdpがブルーの画面のままとなる場合の対応
第2段階 PHPをバージョンアップ
2.1 おまじない
sudo apt update
sudo apt upgrade
2.2 サービス一時停止
sudo systemctl stop mariadb.service
sudo systemctl stop php7.4-fpm.service
sudo systemctl stop apache2.service
2.3 PHP類インストール
sudo apt install php php-mbstring php-gd php-mysql php-pspell
sudo apt install php-xml php-xmlrpc php-fpm php-curl php-imagick php-zip php-intl
バージョン確認
php -v
2.4 インストール中のメッセージ内で言われたとおりの事を行う
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
sudo systemctl reload apache2
sudo systemctl restart apache2
第3段階 PHP8系とwordpressの相性の悪さに対応
wordpressを表示しようとしたところ、fatalエラーや表示されない問題が発生したので対処
3.1 Fatalエラー対策 functions.php
create_functionがPHP8で削除され無くなったらしく、無名関数で対応
sudo nano wp-content/themes/使用しているtheme/functions.php
add_action('widgets_init', function(){register_widget("My_Widget_Meta");});
下記を上記の様に書き換える
# add_action('widgets_init', create_function('', 'return register_widget("My_Widget_Meta");'));
3.2 内容が表示されない問題対応 single.php, index.php, archive.php
クォーテーションで囲まれてないと「Use of undefined constant」というエラーになる様になった。自作のPHPファイルなのでその様なところが残っていた。 自作でなければ必要ないかも
sudo nano wp-content/themes/使用しているtheme/single.php
下記の場合、DATA_W3Cをシングルクォートで囲む様に書き換えた。
esc_attr( get_the_date( 'DATA_W3C' ) ); ?>">
同様にindex.php と archive.php 内の DATA_W3C をシングルクォートで囲む。
esc_attr( get_the_date( 'DATA_W3C' ) ); ?>">
3.3 他にhtml5とコメントで名前とメールが入力必須になっているかの判断のところうまく動かなくなっていたので、そこを暫定的に決め打ちした cooments.php
comments.php の先頭に下記を追加
<?php
$aria_req = " aria-required='true'" ;
?>
comments.php で$html5 を使っているところを使っていることに決め打ちする。
下記
'<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' .
下記の様にする
'<input id="email" name="email" ' . 'type="email"' . ' value="' .
おしまい
これで、復活し、wordpressのサイトヘルスでも怒られなくなった
Leave a Comment