How to Upgrade WordPress to PHP 8.0 on Ubuntu Linux

This brief tutorial shows students and new users how to use PHP 8.0 with WordPress on Ubuntu 20.04 | 18.04.

The WordPress team encourages all users to run the latest and greatest versions of PHP. So if PHP 8.0 is fully supported, you may want to upgrade to it and make use of its newest features and enhancements that were released.

At this moment, PHP 8.0 is not ready to be used with WordPress. WordPress 5.6 which is being released in a couple of weeks as of this date, might support it, but developers are still calling WordPress 5.6 “beta compatible” with PHP 8.0.

If PHP 8.0 works with core WordPress functions, I doubt all themes and plugins will work without issues at this moment.

If you haven’t installed WordPress, search our website to learn how to install it on Ubuntu.

Upgrade to PHP 8.0 with Nginx

If you’re running Nginx on Ubuntu to support WordPress, the steps below show you how to upgrade to PHP 8.0-FPM.

This post assumes that you’re running PHP 7.4 or previous.

Ubuntu does not have PHP 8.0-FPM packages available in its default repositories. To install the latest versions of PHP on Ubuntu you may have to add third-party repositories.

Simply run the commands below to add the below repository to Ubuntu.

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Then update and upgrade to PHP 8.0-FPM

sudo apt update

Next, run the commands below to install PHP 8.0-FPM and related modules.

sudo apt install php8.0-fpm php8.0-common php8.0-mysql php8.0-gmp php8.0-curl php8.0-intl php8.0-mbstring php8.0-xmlrpc php8.0-gd php8.0-xml php8.0-cli php8.0-zip

After installing PHP 8.0-FPM, run the commands below to open Nginx’s PHP default configuration file.

sudo nano /etc/php/8.0/fpm/php.ini

The lines below are a good setting for most PHP-based CMS… Update the configuration file with these and save.

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

You should restart the Nginx web server and PHP script every time you make changes to the PHP configuration file.

To do so, run the commands below:

sudo systemctl restart nginx.service
sudo systemctl restart php8.0-fpm.service

After that, run the commands below to enable PHP 8.0 support for Nginx.

Open the current WordPress virtual host site configuration file and enable the PHP block to use PHP 8.0-FPM.

Ubuntu default site configuration file can be found at

sudo nano /etc/nginx/sites-available/default

Then edit the PHP block session:

# Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;


        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one

After that, restart the Nginx HTTP server to use PHP 8.0-FPM.

sudo systemctl restart nginx.service

Finally, run the commands below to remove all PHP 7.4-FPM packages.

sudo apt-get purge `dpkg -l | grep php7.4| awk '{print $2}' |tr "\n" " "`

Doing that will prompt you to accept the changes to your system. then type Y to continue. When you’re done, PHP 8.0-FPM should be enabled and PHP 7.4-FPM completely removed from Ubuntu.

If you’re running PHP 7.3 or previously, replace 7.4 with your specific PHP version number to remove it from Ubuntu.

Upgrade to PHP 8.0 with Apache2

Skip the above steps if you’re running WordPress on an Apache2 HTTP server.

Apache2 runs on PHP 8.0 while Nginx runs on PHP 8.0-FPM.

Again, Ubuntu may not have PHP 8.0 packages available in its default repositories. To install PHP 8.0 on Ubuntu to support WordPress, you may need to run the commands below to add a third-party repository.

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

After adding the repository above, update and install PHP 8.0

sudo apt update

Next, run the commands below to install PHP 8.0 and related modules.

sudo apt install php8.0 libapache2-mod-php8.0 php8.0-common php8.0-mysql php8.0-gmp php8.0-curl php8.0-mbstring php8.0-xmlrpc php8.0-gd php8.0-xml php8.0-cli php8.0-zip

After installing PHP 8.0, run the commands below to open Apache’s PHP default configuration file.

sudo nano /etc/php/8.0/apache2/php.ini

The lines below are a good setting for most PHP-based CMS… Update the configuration file with these and save.

file_uploads = On
allow_url_fopen = On
short_open_tag = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

For Apache2 and PHP 8.0, you must disable previous versions of PHP and enable Apache2 to use the latest version.

First, run the commands below to disable PHP 7.4.

sudo a2dismod php7.4

Now that PHP 7.4 is disabled, run the commands below to enable PHP 8.0.

sudo a2enmod php8.0

After enabling PHP 8.0, run the commands below to restart Apache2 and PHP 8.0 should be used to support WordPress.

sudo systemctl restart apache2.service

Finally, run the commands below to remove all PHP 7.4 packages.

sudo apt-get purge `dpkg -l | grep php7.4| awk '{print $2}' |tr "\n" " "`

That’s it!

Conclusion:

This post shows you how to upgrade to the latest PHP 7.4 to support WordPress sites on Ubuntu systems. If you find any error above, please report it in the comment form below.

You may also like the post below: