Switching WordPress to another PHP version
|I share my posts here on a total of 3 blogs, once this one, then the german-language one on tuxoche.de and my photos on belichtungszeit-zeit.net. What they all have in common is that the wordpress installations in question run on PHP 7.4.
Introduction
Up to now I had no problems with all my blogs running on PHP 7.4. After all, I have always kept the WordPress version up to date. This means that plugins and WordPress itself are up to date, but not PHP. There we are now at version 8.2 more precisely 8.2.5, which brings some changes.
According to WordPress, PHP 7.4 is still one of the minimum requirements. However, the PHP version from 8.0 upwards officially still belong to the beta status in WordPress.
On the other hand, PHP 7.4 no longer receives security updates since the beginning of this year. So an update is urgently needed. You are in a bit of a dilemma, if PHP 7.4 is no longer supported, but on the other hand WordPress itself ain the latest version 6.2 is probably not fully converted to the PHP version.
The problem with the update
No matter if you decide to use PHP version 8.0 or even the latest version 8.2. So you can not be sure that everything in WordPress and especially in the many plugins that exist so, then really works.
So you first have to test if and with which PHP version your site runs on WordPress without problems. This can be done most easily locally, in a virtual machine or on a server.
I have recorded a short video.
PHP 7.4, 8.0 or even 8.2
Almost all Linux distributions offer a LAMP stack, an option to install Apache as webserver, Mysql or MariaDB as database and of course PHP. There Manager has now after the state of the distribution just a PHP version 8.x running.
So you can’t really try it out. But independent of this difficulty, a Linux installation without a graphical
graphical user interface needs only few resources, so that one can install this really almost everywhere in a virtual machine with VirtualBox or other programs. 2 CPU cores and 512 MB RAM are at least enough to try it out. More is better to some extent, but only when upgrading the distribution for the first time.
On a Proxmox server I got exactly these values for a LXC. Well the database runs extra for me, so you might want to take 1 GB of memory.
How much space is needed on a (virtual) harddisk depends on your own site and if you want to set it up completely local, for example, to customize it.
The installation steps
I then tried it out on an installation with a current Ubuntu 22.04. First, of course, the installation is brought up to date via apt update && apt upgrade. Then the installation of the Apache2 webserver follows with
apt install apache2
If it is installed correctly, you should see the default website when you call http://Ip-Adresse.
Now comes PHP. Here there is alternative repository that allows this change we needed. For this we have to add the repository with:
apt-add-repository ppa:ondrej/php
This alternative is also available for Debian. If you get a nagging message that apt-add-repository is not available, install it with apt install software-properties-common. Now you can install the different PHP versions with apt install php8.1, 8.2 or even 7.4. These can be selected with update-alternatives –config php, but only for the command line.
FFor the webserver you can activate or deactivate the different modules with a2dismod or a2endmod. After that don’t forget to restart apache2 with
systemctl restart apache2
to restart the webserver.
The result
With this option you can now switch to PHP version 7.4 and test if your website runs.
If you find out that everything works you can try to switch to PHP version 8.1 or even 8.2. This way you have a test environment and you don’t have to mess up the real site.
Conclusion
This option opens the possibility to test your own website without any danger and to try out if you can/should switch to a newer PHP version or even MySQL version. And the effort is relatively small in comparison to. a perhaps shot up web page, which one must repair then expensively. Such a test scenario becomes a must if you can update, but in case of a case you can’t do a rollback to the old version. This would have to be clarified with the hosting provider first.
ciao tuxoche