Security warning, 22 October 2026: PHP 8.0 is end of life and gets no official fix for the PHP2Shell vulnerabilities (CVE-2026-109618 and CVE-2026-109619), which allow remote code execution without logging in. Don’t install PHP 8.0 on a public server. Upgrade to PHP 8.4 or PHP 8.5 instead. If you have to keep PHP 8.0 briefly, only use a vendor build that backports the fixes and check that its changelog lists both CVEs. See my PHP2Shell guide for details.
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
switchthat 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 onnullwithout 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 functions:
str_contains(),str_starts_with(), andstr_ends_with()replace verbosestrpos()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 -mon 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, since 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:
- PHP 7.4 → PHP 8.0: this guide
- PHP 8.0 → PHP 8.2: PHP 8.2 upgrade on Ubuntu (security support until December 2026)
- PHP 8.0 → PHP 8.4: PHP 8.4 upgrade on Ubuntu (current stable release, recommended for new deployments)
- PHP 8.4 → PHP 8.5: PHP 8.5 upgrade on Ubuntu
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.


