How to Upgrade WordPress to PHP 8.0 on Ubuntu Linux

|

|

The tutorial guides on how to upgrade to PHP 8.0 with WordPress on Ubuntu 20.04 | 18.04, amidst WordPress’s caution against early adoption due to probable theme and plugin issues. Detailed steps are given for those running WordPress on Nginx and Apache2. PHP 8.0 pack installation requires adding a third-party repository with the PHP 8.0…

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 most excellent 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.

Currently, PHP 8.0 is not ready to be used with WordPress. WordPress 5.6, released in a couple of weeks 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.

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

Restarting the Nginx web server and PHP script would be best whenever you change 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 done, PHP 8.0-FPM should be enabled, and PHP 7.4-FPM should be removed entirely 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 turn off 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, please report it in the comment form below.

You may also like the post below:


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



3 responses to “How to Upgrade WordPress to PHP 8.0 on Ubuntu Linux”

  1. Ziggy Avatar
    Ziggy

    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. Atul Host Avatar
    Atul Host

    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.

  3. nAn Avatar
    nAn

    The “php78.0-xmlrpc” should be “php8.0-xmlrpc”.

Leave a Reply

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

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading