How to Update to PHP 8.1 for WordPress Site on Debian 10 / 11
In this article I am going to show you how I managed to update to PHP 8.1 for my WordPress Site. I am running this WordPress site on top of Debian 10. I had this notification on the WordPress dashboard telling that I should upgrade my PHP to the latest version. I was running PHP 7.3.
As you notice on the picture above, PHP Update Required. Since I do not host my websites on a managed hosting provider, I had to do this PHP update manually. So in this article, you will find out how to manually upgrade your PHP installation to version 8.1.
- Please don’t forget, if you are root you don’t need to use sudo in your commands.
- And always have a Backup of your Data! ( After my Desaster -.-” )
Step 1: First, let’s check our PHP version installed on our system:
php -v
The Output should be something like::
PHP 7.3.33-0 (cli) (built: Nov 19 2021 19:34:46) ( NTS )
Copyright (c) 1997-2021 The PHP Group Zend Engine v4.0.0, Copyright (c) 1998-2021 Zend Technologies
with Zend OPcache v7.3.33-0, Copyright (c) 1999-2021, by Zend Technologies
As you can see, my current PHP version is 7.3.33.
Step 2: It is recommended to update the Debian system prior to the upgrade
sudo apt update && apt upgrade
Maybe you will also need to reboot Debian.
Step 3: Configure PHP 8.1 Repository – Run the following command to install some packages and download the gpg key for Sury 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
Finally, use this command to add the repository
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
Step 4: Update…..
sudo apt update -y
….. and Upgrade the system
sudo apt upgrade -y
After the upgrade, the PHP 8.1 command pulls from the repository and updates your PHP version. If you enter php -v you will already see the new version.
root@irg-NET-wp01:~# php -v
PHP 8.1.2 (cli) (built: Jan 27 2022 12:20:56) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies
But maybe not under WordPress Dashboard > Tools > Site Health > Info > Server. It could be that PHP 7.3 is still displayed there.
Step 5: To fix this, we have to disable the PHP 7.3 version, enable the PHP 8.1 and restart apache2
sudo a2dismod php7.3
sudo a2enmod php8.1
sudo systemctl restart apache2
And finally we will get the correct version in WordPress too
And that’s it! If you have any questions please leave it in the comments. 🙂