14+ years building on WordPress / Replies in under 5 hours
PHP 7 min read · Updated July 2026

Upgrade PHP to 8.0 on Ubuntu: Step-by-Step Guide

Photo of Ajay Khandal
Ajay Khandal
WordPress Developer
TL;DR

Upgrade PHP to 8.0 on Ubuntu: add the Ondrej Sury PPA (ppa:ondrej/php), install php8.0 and its extensions, then switch Apache with a2dismod/a2enmod or update your Nginx fastcgi_pass socket to php8.0-fpm.sock. Run sudo update-alternatives --config php if the CLI still reports the old version. Note: PHP 8.0 reached end-of-life in November 2023 — after upgrading, plan to continue to PHP 8.2 or 8.4, which are under active security support.

PHP 8.0 was released in November 2020 and brought the most significant language additions to PHP in years: a JIT compiler, named arguments, match expressions, the nullsafe operator, union types, and constructor property promotion. It also reached end-of-life in November 2023, meaning it no longer receives security patches.

This guide covers the exact steps to upgrade to PHP 8.0 on Ubuntu using the Ondrej Sury PPA — the standard third-party PHP repository that provides all PHP versions ahead of official Ubuntu package support. If you’re upgrading from PHP 7.4, this is the right next step; the guide assumes Apache or Nginx as your web server and covers both. If you’re on a fresh server or have flexibility on the target version, skip ahead to the PHP 8.4 upgrade guide — 8.4 is the current stable release and the better long-term choice for new deployments.

What’s New in PHP 8.0

  • JIT compiler — PHP 8.0 introduced a Just-In-Time compiler as an experimental feature. For typical web applications (WordPress, Laravel, Symfony), JIT’s practical performance gain is modest — CPU-bound tasks see the most benefit. The more significant gains come from the engine optimisations that shipped alongside it.
  • Named arguments — Function calls can now pass arguments by parameter name rather than position: array_slice(array: $a, offset: 1, preserve_keys: true). Useful for functions with optional parameters deep in the signature.
  • Match expressions — An alternative to switch that returns a value, uses strict comparison (===), and has no fall-through behaviour. More concise and less error-prone than switch for value mapping.
  • Nullsafe operator (?->) — Method chains and property accesses that short-circuit on null without nested null checks: $user?->getProfile()?->getAvatar().
  • Union types — Type declarations can now accept multiple types: int|string, array|null. More flexible than the previous nullable-only syntax.
  • Constructor property promotion — Properties can be declared and initialised directly in the constructor signature: public function __construct(public readonly string $name) {}.
  • Attributes — Native PHP annotations via #[Attribute] syntax, replacing PHPDoc-based metadata conventions.
  • New string functionsstr_contains(), str_starts_with(), and str_ends_with() replace verbose strpos() checks for common string tests.

Before You Upgrade

Run this checklist before changing anything on a production server:

  • Test on staging first. A PHP version change is the kind of change most likely to surface a compatibility issue in a plugin or custom code that looks fine until it runs. See how to set up a WordPress staging environment for the safe workflow — apply the upgrade there first and verify the site before touching production.
  • Back up your database and files. Any time you’re changing server configuration, take a fresh backup first. A bad upgrade is recoverable from a backup; it’s much harder without one.
  • Check your application’s PHP compatibility. WordPress 6.x requires PHP 7.4+ and recommends 8.0+, so moving to 8.0 is well within the supported range. For custom plugins or third-party code, check the developer’s stated PHP compatibility before upgrading.
  • Note your current extension list. Run php -m on the server to list all active PHP modules. You’ll reinstall extensions for PHP 8.0; knowing what’s active now means you won’t miss one.

Step 1: Check the Current PHP Version

Confirm what’s currently running before making changes:

php -v

On Apache with multiple PHP versions, the CLI version and the web server version can differ. To check which PHP version Apache is serving, create a temporary info file:

echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/phpinfo.php

Load http://your-server-ip/phpinfo.php in a browser and look at the PHP Version line. Delete the file immediately after checking — it exposes server configuration publicly:

sudo rm /var/www/html/phpinfo.php

Step 2: Add the Ondrej Sury PPA

Ubuntu’s official package repositories don’t carry all PHP versions promptly. The Ondrej Sury PPA is the standard source for PHP packages on Ubuntu — it’s maintained by the Debian PHP maintainer and is widely used in production environments:

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

If you’ve previously run this PPA for an earlier PHP version, the add-apt-repository line may report that the PPA is already configured — that’s fine, run sudo apt-get update and continue.

Step 3: Install PHP 8.0 and Extensions

Install the PHP 8.0 interpreter:

sudo apt install php8.0 -y

Then install the extensions. This set covers WordPress and most PHP web applications:

sudo apt install php8.0-common php8.0-mysql php8.0-xml php8.0-xmlrpc php8.0-curl php8.0-gd php8.0-imagick php8.0-cli php8.0-dev php8.0-imap php8.0-mbstring php8.0-opcache php8.0-soap php8.0-zip php8.0-intl -y

For sites using Redis as an object cache, also install:

sudo apt install php8.0-redis -y

Compare this list against the output of php -m you noted earlier and install any additional extensions your application requires.

Step 4a: Switch Apache to PHP 8.0

If you’re running Apache with mod_php, disable the current PHP module and enable the PHP 8.0 one:

sudo a2dismod php7.4
sudo a2enmod php8.0
sudo service apache2 restart

Replace php7.4 with whichever version is currently active if you’re coming from a different version. After restarting, verify Apache is using PHP 8.0 by checking the server info or running:

php -v

Step 4b: Switch Nginx to PHP 8.0 (PHP-FPM)

Nginx doesn’t use mod_php — it communicates with PHP via FastCGI (PHP-FPM). Install the PHP 8.0 FPM package:

sudo apt install php8.0-fpm -y
sudo systemctl enable php8.0-fpm
sudo systemctl start php8.0-fpm

Update your Nginx site configuration to point to the PHP 8.0 FPM socket. In your server block, change the fastcgi_pass directive:

# Change from:
fastcgi_pass unix:/run/php/php7.4-fpm.sock;

# To:
fastcgi_pass unix:/run/php/php8.0-fpm.sock;

Then test the Nginx config and reload:

sudo nginx -t
sudo systemctl reload nginx

You can also stop the old FPM service if you no longer need it:

sudo systemctl disable php7.4-fpm
sudo systemctl stop php7.4-fpm

Step 5: Verify the Upgrade

Check the PHP CLI version:

php -v

The output should show PHP 8.0.x. If the CLI still reports an older version, update the system-wide PHP CLI alternative:

sudo update-alternatives --config php

This command lists all installed PHP versions and lets you select the default. Enter the number corresponding to PHP 8.0 and press Enter.

After updating, confirm with php -v again. Also verify your web server is serving PHP 8.0 by checking the response headers or a temporary phpinfo() page as described in Step 1.

Troubleshooting

Apache shows a 500 error after the module switch: Check the Apache error log (sudo tail -f /var/log/apache2/error.log). A common cause is a PHP extension that’s installed for the old version but not yet for 8.0. Re-run the extension install command in Step 3 and restart Apache.

Nginx returns a 502 Bad Gateway: PHP-FPM isn’t running or the socket path is wrong. Run sudo systemctl status php8.0-fpm to check. If it’s not running, sudo systemctl start php8.0-fpm. If the socket path differs from what’s in your Nginx config, check the actual socket path: ls /run/php/.

WordPress admin shows a white screen after the upgrade: Enable WordPress debug mode (define('WP_DEBUG', true); in wp-config.php) and reload the page to see the error output. Usually a plugin compatibility issue — deactivate plugins one at a time to isolate the cause. See the WordPress white screen of death fix guide for the full diagnostic workflow.

The PHP Upgrade Series for Ubuntu

PHP 8.0 reached end-of-life in November 2023. If you’ve just arrived here from PHP 7.4, upgrading to 8.0 as an intermediate step is reasonable when an application’s compatibility floor requires it — but plan to continue to a supported version promptly. The recommended path:

The process for each step is the same as above — swap the version number in every command. Extension availability via the Ondrej Sury PPA is consistent across all versions on Ubuntu 20.04 LTS and 22.04 LTS.

For PHP upgrades on a WordPress site, keeping WordPress and its plugins current alongside the PHP upgrade reduces compatibility risk significantly. See how to update WordPress safely for the recommended update sequence.

Frequently asked questions

PHP 8.4 is the current stable release and the recommended version for new deployments in 2026. PHP 8.3 and 8.2 remain under active security support. PHP 8.0 and 8.1 reached end-of-life in November 2023 and December 2025 respectively — they no longer receive security patches and should not be running on production servers. If you're currently on PHP 8.0, upgrade to PHP 8.2 or 8.4 as soon as possible: the process is identical to this guide, just substituting the higher version number in each command.

The Ondrej Sury PPA (ppa:ondrej/php) is a third-party Ubuntu package repository maintained by Ondrej Sury, the Debian PHP packages maintainer. It provides all current and recent PHP versions for Ubuntu LTS releases ahead of Ubuntu's own package timelines — Ubuntu 22.04 ships PHP 8.1, for example, while the PPA provides 8.0 through 8.4+. It's the standard source for PHP on Ubuntu in production environments and is widely used by hosting providers. The packages are signed, the maintainer is a known member of the PHP/Debian ecosystem, and the repository has a long track record. It is not an official Canonical or PHP Group resource, but there is no better-maintained alternative for PHP version management on Ubuntu.

Run php -v in the terminal to check the PHP CLI version. For Apache, the web server may use a different PHP version than the CLI — create a temporary file at /var/www/html/phpinfo.php containing and open it in a browser to see the PHP version Apache is actually using. Delete the file immediately after checking. For Nginx with PHP-FPM, check which FPM service is running: systemctl list-units | grep php-fpm and confirm the fastcgi_pass socket path in your Nginx site config matches the active FPM service.

WordPress's minimum required PHP extensions are: curl, dom, exif, fileinfo, hash, igbinary, imagick, intl, mbstring, mysqli, openssl, pcre, xml, and zip. The full recommended set for a WordPress site on PHP 8.0 is: php8.0-mysql (for mysqli/PDO_MySQL), php8.0-xml, php8.0-curl, php8.0-gd, php8.0-imagick, php8.0-mbstring, php8.0-opcache, php8.0-zip, php8.0-intl, php8.0-soap, and php8.0-imap. OPcache is included in the php8.0-opcache package — enable it in php.ini for significant performance gains. If you use Redis as an object cache, also install php8.0-redis.

Nginx uses PHP-FPM (FastCGI Process Manager) rather than mod_php. To switch to PHP 8.0: install php8.0-fpm (sudo apt install php8.0-fpm), start it (sudo systemctl start php8.0-fpm), then update the fastcgi_pass directive in your Nginx server block from unix:/run/php/php7.4-fpm.sock to unix:/run/php/php8.0-fpm.sock. Test the config (sudo nginx -t) and reload (sudo systemctl reload nginx). You can confirm the socket path with ls /run/php/ after starting the FPM service.

sudo update-alternatives --config php manages which PHP binary the system uses as the default 'php' command. When multiple PHP versions are installed, running php -v might still report an older version even after installing PHP 8.0 — because the 'php' symlink still points to the old binary. Running sudo update-alternatives --config php lists all installed PHP CLI binaries and lets you select which one 'php' should point to. This only affects the CLI default; it doesn't change which PHP version Apache or Nginx serves — those are controlled by Apache's a2enmod/a2dismod or the Nginx fastcgi_pass socket path.

Photo of Ajay Khandal

Written by Ajay Khandal

I'm a freelance WordPress developer with 14+ years of experience building, fixing, and speeding up sites for businesses, agencies, and store owners across the US, UK, Europe, and Australia. I specialize in custom themes, WooCommerce, and performance — the kind of work that shows up as faster load times and fewer support tickets. No account managers, no outsourced tickets — you work directly with me, with replies typically inside 5 hours.

Work with me →