Upgrade WordPress to PHP 8.0 on Ubuntu 20.04 | 18.04

desktop 1389979 640

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

The team at WordPress continues to encourage 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 couple of weeks as of this date, might support it, but developers are still calling WordPress 5.6 “beta compatible” to 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.

However, if you really, really want to give it a shot, simply continue below upgrade to PHP 8.0 and use it with WordPress.

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.

Currently, Ubuntu does not have PHP 8.0-FPM packages available in its default repositories. In order 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 PHP default configuration file for Nginx.

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

The lines below is a good settings 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

Everytime you make changes to PHP configuration file, you should also restart Nginx web server and PHP script.

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 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 previous, replace 7.4 with your specific PHP version number to remove from Ubuntu.

Upgrade to PHP 8.0 with Apache2

Skip the above steps if you’re running WordPress on 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 to 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 php78.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 PHP default configuration file for Apache.

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

The lines below is a good settings 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 disable, 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 use the comment form below to report it.

You may also like the post below:

2 Comments

  1. Great tutorial. Thank you!

    Btw, I get an error when installing PHP 8.0-FPM and related modules.

    E: Unable to locate package php8.0-xmlrpc
    E: Couldn’t find any package by glob ‘php8.0-xmlrpc’
    E: Couldn’t find any package by regex ‘php8.0-xmlrpc’

    It may be because:
    “xmlrpc extension is moved to PECL with good reasons. Software repositories mentioned in this post does not include xmlrpc extension for PHP 8.0.”

    source: https://php.watch/articles/php-8.0-installation-update-guide-debian-ubuntu

    How to install the php8.0-xmlrpc correctly?

  2. PHP 8 is definitely impressive in terms of performance, but the code is totally new and incompatible with earlier ones. Any quick update should be avoided, at least for the first few weeks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.