I’ve updated the Terms and Conditions for using this website. Take a look!

How to Upgrade from PHP 7.4 to PHP 8.1 in Virtualmin on Debian

PHP 7.4 is now officially deprecated as of November of 2022. This means you should upgrade your PHP installation as soon as possible to avoid security vulnerabilities.

Please note that this article assumes you have root SSH access to your server, as well as control over your virtual server’s PHP version in Virtualmin.

How to Install PHP 8.1 for WordPress in Debian

How to Install PHP 8.1 for WordPress in Debian

Install PHP 8+ Repository

The Debian repository doesn’t have an official PHP 8 package yet (Ubuntu does), so you will first need to add a new repository to your sources list, shown below.

## Source: https://php.watch/articles/install-php82-ubuntu-debian ##

sudo apt install apt-transport-https lsb-release ca-certificates wget -y
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update

Install PHP 8.1

Install PHP 8.1, along with all of the most important PHP 8.1 packages for WordPress.

sudo apt install php8.1 php8.1-fpm php8.1-mysql php8.1-imagick php8.1-zip php8.1-xml php8.1-mbstring

How to Switch to PHP 8.1 in Virtualmin

Now you need to log into your Virtualmin instance and change the PHP version from 7.4 to 8.1. It is very important that you take this step before removing the older version of PHP. To do this, go to Virtualmin > Server Configuration > PHP Options. Change the PHP Options to 8.1.* and click save. Once this process is complete, reload your website and ensure everything works correctly.

Virtualmin Change PHP 7.4 to PHP 8.1

You may need to switch back to PHP 7.4 and then deactivate problem plugins if you run into any errors (see below for how to debug which plugins are causing any errors that might occur during this step). You may also want to update all of your plugins to the latest versions available before making the change to PHP 8.1, which should hopefully prevent errors from occurring.

Finally, once everything looks good, remove PHP 7.4 from your server.

sudo apt purge php7.4*

Errors When Switching PHP Versions

WordPress Errors

If you experience a WordPress error when you upgrade to PHP 8.1, you can determine the plugin that is causing this problem. In Virtualmin, go to the File Manager. Right-click the wp-config.php file on your server and select the “Edit” option. Go to the line in the file where it says define( 'WP_DEBUG', false ); and change it to the following:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

Make sure to save the file. Reload the website page that is causing the error, and then check out the log file that was created in the wp-content directory:

YourWebsiteDirectory/wp-content/debug.log

In the log, scroll down to the last dated entry. This entry will probably be multiple lines long, so just look for a date and time stamp to find the beginning of the error entry. Once you find the last entry, look for a file location line that says SomeDirectory/wp-plugins/SomePlugin/OtherStuff. The part after wp-plugins is the plugin directory of the plugin causing the problem. For example, if it were to be wp-plugins/woocommerce you would know WooCommerce was the problem plugin.

Once again, making sure all your plugins are updated to the latest version available will hopefully prevent these kind of errors from occurring.

502 Error

I experienced this error when I removed PHP 7.4 before I switched to PHP 8.1 in the Virtualmin settings. This is because Virtualmin makes some changes to the config files behind the scenes while switching PHP versions, and removing all of the versions of PHP but one will skip that important step. If this happens to you, install another version of PHP, like PHP 8.2. Then switch to that PHP version in Virtualmin (Virtualmin > Server Configuration > PHP Options), and then switch again right back to PHP 8.1. Hopefully that will resolve your problem.

Comments on "How to Upgrade from PHP 7.4 to PHP 8.1 in Virtualmin on Debian"

Leave the first comment


X

Be in the Know

Subscribe to be in the know about new articles and giveaways, like free Bricks Builder templates. The most I will email you is once every two weeks.