My WordPress admin center was complaining for a long time that I should upgrade WordPress to PHP7.4.
And from experience, I knew that this will typically not go without any hiccups. Be aware of any risks performing this upgrade and consider at least having a backup available, better even using a staging environment e.g. with UpdraftClone.
So here are the steps I have performed to make WordPress run again on that (not really) new PHP version 7.4.
My WordPress was running on a Raspberry Pi4, with Raspberry Pi OS 10 (buster) Version, mariaDB 10.3.39, PHP 7.3, and Apache 2
First, you should check, if there are any indications that your WordPress plugins and theme is not working with the new PHP version.
Then bring your OS to the latest version.
# sudo apt update # sudo apt upgrade -y
Then install the certificate and add the repository.
# sudo apt -y install lsb-release apt-transport-https ca-certificates # sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg # echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
Install the following packages.
# sudo apt update # sudo apt install php7.4 php7.4-fpm php7.4-mysqli # sudo apt-get install php7.4-{bcmath,bz2,intl,gd,mbstring,mysql,zip,curl,dom,imagick,mbstring,intl}
You can check if the command line interface (cli) for PHP is running the new version with:
# php -v PHP 7.4.33 (cli) (built: Jun 9 2023 07:38:14) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
As we are running the Apache web server with PHP we have to configure it now with the new version.
For switching between different PHP versions on a command line interface use the following commands:
# sudo update-alternatives --set php /usr/bin/php7.4 # sudo update-alternatives --set phar /usr/bin/phar7.4 # sudo update-alternatives --set phar.phar /usr/bin/phar.phar7.4
You can also have multiple PHP versions on your system and switch with the following configurations between them for the Apache web server and WordPress.
# sudo a2disconf php7.3-fpm
# sudo a2dismod php7.3
# sudo a2enmod php7.4
# sudo a2enconf php7.4-fpm
We also have to replace the proxy entries in all the sites from the virtual hosts you are running with Apache (folder „sites-available“). Look for the lines:
<FilesMatch \.php$> # 2.4.10+ can proxy to unix socket SetHandler "proxy:unix:/run/php/php7.3-fpm.sock|fcgi://localhost" </FilesMatch>
And set the version to php7.4-fpm.
Now it’s time to restart the Apache web server.
# sudo service apache2 restart
Check with phpinfo() if the php configuration for Apache is working correctly. The new version 7.4 with a mysqli section should be shown.
Checkout the following references: