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

How to Upgrade PHP to 8.4 on Ubuntu

AK
Ajay Khandal
WordPress Developer
Effortless Guide to Upgrade PHP to Version 8.4 on Ubuntu
TL;DR

Five steps to upgrade PHP to 8.4 on Ubuntu: (1) add the Sury PPA — <code>sudo add-apt-repository ppa:ondrej/php && sudo apt update</code>; (2) install PHP 8.4 and extensions — <code>sudo apt install php8.4 php8.4-fpm php8.4-mysql php8.4-mbstring php8.4-xml php8.4-curl php8.4-opcache php8.4-zip</code>; (3) Apache: <code>sudo a2dismod php8.x && sudo a2enmod php8.4 && sudo service apache2 restart</code> (correct mod package: <code>libapache2-mod-php8.4</code>) — Nginx: update <code>fastcgi_pass</code> to <code>php8.4-fpm.sock</code> and <code>sudo systemctl restart php8.4-fpm nginx</code>; (4) update CLI default: <code>sudo update-alternatives --config php</code>; (5) verify: <code>php -v</code>. PHP 8.4 key additions: property hooks (get/set syntax on class properties), asymmetric visibility (<code>public private(set)</code>), <code>array_find()</code> / <code>array_any()</code> / <code>array_all()</code>, new HTML5 DOM parser (<code>DomDocument</code>), <code>#[Deprecated]</code> attribute.

PHP 8.4 is the current stable release on the 8.x branch, introducing property hooks, asymmetric visibility, new array utility functions, and a proper HTML5 DOM parser. It also carries active security support and measurable performance improvements over 8.2 and 8.3. This covers the exact steps to upgrade from any earlier PHP version to 8.4 on Ubuntu using the Ondrej Sury PPA — the standard third-party PHP repository for Ubuntu that provides all PHP versions ahead of official Ubuntu package support.

What’s new in PHP 8.4

  • Property hooksget and set logic can now be defined directly on class properties without writing separate getter/setter methods. This is the most impactful syntax addition in 8.4.
  • Asymmetric visibility — properties can be declared public private(set), making them publicly readable but only writable from within the class. Replaces common readonly workarounds.
  • New array functionsarray_find(), array_find_key(), array_any(), and array_all() reduce the need for verbose array_filter/array_map combinations.
  • New HTML5 DOM parserDom\Document replaces the older libxml2-based parser with a Lexbor-based HTML5 parser that handles modern HTML markup correctly.
  • #[\Deprecated] attribute — code can mark its own APIs as deprecated using a native PHP attribute rather than relying on docblocks or trigger_error().
  • JIT improvements — reduced compilation overhead and more stable JIT output for CPU-intensive and long-running CLI workloads.

Prerequisites

  • Ubuntu 20.04, 22.04, or 24.04 (this process works on all current LTS releases)
  • SSH or terminal access with sudo privileges
  • A backup of your application code and database — extension incompatibility is the most common failure mode on the first upgrade attempt
  • A staging environment to test the upgrade before applying to production if available — see how to set up a WordPress staging site

Add the Ondrej Sury PPA

The Sury PPA is the standard PHP package source for Ubuntu — it provides all PHP versions from 7.4 through 8.5, updated alongside official PHP releases. Ubuntu’s default apt repositories lag behind official PHP releases, particularly for non-LTS PHP versions, so the PPA is required for PHP 8.4 on Ubuntu 20.04, 22.04, and 24.04.

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

Install PHP 8.4 and required extensions

Install the base package and the extensions your application needs. The list below covers a typical WordPress or PHP application stack:

sudo apt install php8.4 \
  php8.4-common \
  php8.4-cli \
  php8.4-fpm \
  php8.4-mysql \
  php8.4-curl \
  php8.4-opcache \
  php8.4-mbstring \
  php8.4-xml \
  php8.4-zip \
  php8.4-readline

Additional extensions commonly needed: php8.4-gd for image processing, php8.4-intl for internationalization, php8.4-redis for Redis object caching, php8.4-imagick for ImageMagick integration. Install only what your application explicitly requires — unused extensions add overhead to every PHP process.

Switch to PHP 8.4 on Apache

If you’re running Apache with mod_php (the standard single-server setup), disable the current PHP module and enable the 8.4 module:

sudo a2dismod php8.2   # replace 8.2 with whichever version is currently active
sudo a2enmod php8.4
sudo service apache2 restart

The correct Apache mod_php package name is libapache2-mod-php8.4 — install it if the a2enmod php8.4 step reports the module as unavailable:

sudo apt install libapache2-mod-php8.4

If you’re using Apache with PHP-FPM (via proxy_fcgi), enable the required Apache modules and update the configuration to point to the PHP 8.4 FPM socket:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
sudo service apache2 restart
sudo systemctl restart php8.4-fpm

Switch to PHP 8.4 on Nginx

Nginx uses PHP-FPM rather than a built-in PHP module. Update your site configuration to point to the PHP 8.4 FPM socket:

# In /etc/nginx/sites-available/your-site, update the fastcgi_pass line:
# fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;

sudo systemctl restart php8.4-fpm
sudo systemctl restart nginx

Update the CLI PHP version

The web server PHP version and the CLI PHP version are managed independently. If php -v in the terminal still shows an older version after the web server switch, update the CLI default:

sudo update-alternatives --config php

Select the entry showing /usr/bin/php8.4. If build scripts use phpize or php-config, update those as well:

sudo update-alternatives --config phpize
sudo update-alternatives --config php-config

Verify the upgrade

php -v

Expected output:

PHP 8.4.x (cli) (built: ...)
...

Additional checks:

  • Load a page on your site and confirm it renders without PHP errors or blank output
  • Create a temporary phpinfo() file and verify the PHP version and loaded extensions match what you installed — delete the file immediately after checking
  • Review PHP-FPM and web server error logs for deprecation notices or fatal errors from your application code

Post-upgrade checks

  • Review php.ini for settings that may have changed defaults in 8.4 — particularly error_reporting, display_errors, and JIT configuration (opcache.jit)
  • Address deprecation notices — PHP 8.4 deprecates several functions available in 8.3; these appear as notices in error logs, not fatal errors, but indicate code to fix before the PHP 9 cycle
  • Confirm all extensions loaded with php -m | grep <extension> for any extension your application explicitly depends on
  • Remove the old PHP version once the upgrade has run stably for 48+ hours: sudo apt purge php8.2* (adjust the version number)

For WordPress sites, PHP 8.4 compatibility depends on installed plugins and the active theme — a plugin using a deprecated or removed function is the most common source of failures. Testing on staging before upgrading production eliminates most surprises. For the monthly PHP version check and update routine that keeps a WordPress server current and secure, see the WordPress maintenance guide. PHP version currency is also one of the core items in the WordPress security practices checklist — older PHP branches stop receiving security patches at end-of-life.

Troubleshooting

Problem Solution
Extension not found or not loading Install via sudo apt install php8.4-<extension>. Confirm loaded with php -m | grep <extension>
Web server still shows old PHP version Disable old mod, enable php8.4, restart web server. For CLI mismatch, run sudo update-alternatives --config php
Nginx PHP-FPM socket permission errors Check listen.owner and listen.group in /etc/php/8.4/fpm/pool.d/www.conf — must match the Nginx user (typically www-data)
WordPress blank page after upgrade Set define('WP_DEBUG', true); in wp-config.php to surface PHP errors. A plugin using a deprecated or removed function is the most common cause — deactivate plugins one by one to isolate
PHP-FPM service fails to start Check sudo journalctl -u php8.4-fpm for the error. A missing extension or malformed php.ini entry is the usual cause

Once PHP 8.4 is stable on your server, the PHP 8.5 upgrade guide covers the next version’s changes and the same upgrade process when you’re ready to move forward.

Frequently asked questions

PHP 8.4's headline additions are structural. Property hooks allow get/set logic to be defined directly on class properties — the most impactful syntax change in the release. Asymmetric visibility adds public private(set) declarations, making properties publicly readable but only writable within the class. New array utility functions — array_find(), array_find_key(), array_any(), and array_all() — cover common search patterns that previously required manual array_filter or array_map combinations. The new DomDocument class uses a proper HTML5 parser (Lexbor) instead of the old libxml2-based parser, which failed silently on modern HTML5 markup. PHP 8.4 also adds the #[Deprecated] attribute for marking APIs as deprecated natively, and includes JIT compiler improvements for CPU-intensive workloads.

The Ondrej Sury PPA is the standard PHP package source for Ubuntu: run sudo apt install software-properties-common -y, then sudo add-apt-repository ppa:ondrej/php, then sudo apt update. This PPA provides all PHP versions from 7.4 through 8.5, updated alongside official PHP releases. Ubuntu's default repositories typically include only one or two PHP versions per LTS release and lag behind official releases, so the Sury PPA is required for PHP 8.4 on Ubuntu 20.04, 22.04, and 24.04. The PPA is maintained by Ondrej Sury, the official PHP package maintainer for Debian.

Minimum required extensions for WordPress on PHP 8.4: php8.4-mysql (database connection), php8.4-curl (HTTP requests and API calls), php8.4-mbstring (multibyte string handling), php8.4-xml (XML parsing used by many plugins), php8.4-zip (plugin and theme installation), php8.4-opcache (bytecode caching — significant performance impact, always enable). Additional extensions commonly required: php8.4-gd or php8.4-imagick for image resizing in the media library, php8.4-intl for multilingual plugin support, php8.4-redis if using Redis object caching (important for WooCommerce performance). Install via sudo apt install php8.4-.

For Apache with mod_php: sudo a2dismod php8.x (disable current version), sudo a2enmod php8.4 (enable new), sudo service apache2 restart. The mod_php package is libapache2-mod-php8.4 — install it first if the a2enmod step reports the module unavailable. For Nginx: update the fastcgi_pass directive in your site config to the new FPM socket path (unix:/var/run/php/php8.4-fpm.sock), then sudo systemctl restart php8.4-fpm nginx. For the CLI default, run sudo update-alternatives --config php and select /usr/bin/php8.4. The web server PHP version and CLI PHP version are independent — both must be updated separately.

Test on a staging server running the same Ubuntu version and web server stack as production. Install PHP 8.4 on staging, enable the same extensions, and run your application through its critical paths — admin login, content pages, form submissions, file uploads, and any cron jobs. Review PHP-FPM error logs for deprecation notices and fatal errors. Deprecation notices in PHP 8.4 are warnings, not fatal errors — they indicate code that will break on PHP 9.0 but won't stop execution now. Fatal errors indicate something actively incompatible that needs fixing before production upgrade. For WordPress, deactivating plugins one at a time is the fastest way to isolate a compatibility failure.

Four checks after upgrade: (1) verify php -v shows 8.4 in CLI, and create a temporary phpinfo() page to confirm the web server PHP version matches — delete the file immediately after; (2) review PHP-FPM error logs for deprecation notices from your application code — deprecations introduced in 8.4 should be addressed before the PHP 9 cycle; (3) confirm all required extensions are loaded with php -m | grep ; (4) run your application through critical paths — login, content, form submissions, checkout if applicable. Once the upgrade has run stably for 48+ hours, remove the old PHP version with sudo apt purge php8.x* to eliminate unmaintained packages from your server.

AK

Written by Ajay Khandal

WordPress Developer — building, fixing and speeding up WordPress sites.

Work with me →