You are currently viewing Updating to PHP 7.4 on Debian for WordPress

Updating to PHP 7.4 on Debian for WordPress

This time, I will cover all the steps I followed to properly update the PHP version that my WordPress site uses. It’s runing on a LXC of Turnkey Linux, but for the most of uses, it’s simply a Debian. This is needed because my WordPress site is complaining about security risks:

Image that shows up a WordPress message, complaining about the seccurity risks of not updating to PHP 7.4.

First of all, we need to update the system, so we execute the following command:

sudo apt update && sudo apt upgrade

With this, we’ve updated the system, and also updated the apt repositories.

Installing PHP on the system

By default, Debians apt repositories won’t have PHP 7.4 to download by default. So we will add a new repo which contains it:

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

Now, let’s add the repo to the list:

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

And then update again the apt repos:

sudo apt update

Now it’s time to install PHP 7.4 on Debian 9/10 using the default apt command, with all the common modules for WordPress:

sudo apt install -y php7.4 php7.4-common php7.4-xml php7.4-mysql php7.4-pdo php7.4-phar php7.4-simplexml php7.4-curl php7.4-mbstring php7.4-imagick php7.4-zip php7.4-gd

With all of this done, now its time to verify PHP’s version:

php -v

The output should be as follows:

user@runesoft ~# php -v
PHP 8.1.12 (cli) (built: Oct 28 2022 18:35:51) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.12, Copyright (c), by Zend Technologies

Enabling new PHP version for Apache

Apache uses a command to enable or disable mods, like PHP, so we should change the default PHP version. Let’s remove the old one:

sudo a2dismod php7.0

Now, enable the new version:

sudo a2enmod php7.4

Restart Apache service to load the changes:

sudo systemctl restart apache2

We should see that now, our WordPress site won’t complain about the security risks of not using the last PHP version (by this time 7.4).

Leave a Reply