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

How to Upgrade PHP to 8.2 on Ubuntu

AK
Ajay Khandal
WordPress Developer
TL;DR

Five steps to upgrade PHP to 8.2 on Ubuntu: (1) add the Sury PPA — <code>sudo add-apt-repository ppa:ondrej/php && sudo apt update</code>; (2) install PHP 8.2 and extensions — <code>sudo apt install php8.2 php8.2-fpm php8.2-mysql php8.2-mbstring php8.2-xml php8.2-curl php8.2-opcache php8.2-zip</code>; (3) Apache: <code>sudo a2dismod php8.x && sudo a2enmod php8.2 && sudo service apache2 restart</code> (correct mod package: <code>libapache2-mod-php8.2</code>) — Nginx: update <code>fastcgi_pass</code> to <code>php8.2-fpm.sock</code> and <code>sudo systemctl restart php8.2-fpm nginx</code>; (4) update CLI default: <code>sudo update-alternatives --config php</code>; (5) verify: <code>php -v</code>. PHP 8.2 key additions: readonly classes (entire class marked readonly), DNF types (<code>(A&B)|null</code>), <code>null</code>/<code>true</code>/<code>false</code> as standalone types, new <code>RandomRandomizer</code> class, <code>SensitiveParameter</code> attribute. Note: PHP 8.2 is in security-support-only mode since December 2024 and reaches end-of-life December 2026 — for new deployments, <a href="/upgrade-php-8-4-ubuntu/">PHP 8.4</a> is the recommended version.

PHP 8.2 introduced readonly classes, disjunctive normal form (DNF) types, null/true/false as standalone types, and the new Random\Randomizer class. As of December 2024 it moved to security-support-only mode (patches continue until December 2026 — after which it reaches end-of-life). For new server deployments, PHP 8.4 is the recommended version; this guide is for upgrades to 8.2 specifically, whether as a stable intermediate step or to match an application’s known compatibility floor. The process uses the Ondrej Sury PPA, which is the standard PHP package source for all Ubuntu LTS releases.

What’s new in PHP 8.2

  • Readonly classes — the readonly modifier can now be applied to an entire class, making all its properties readonly by default rather than annotating each property individually.
  • Disjunctive Normal Form (DNF) types — intersection types can now be combined with union types: (A&B)|null is valid, enabling more precise type declarations without custom interfaces.
  • null, true, and false as standalone types — these can now be used as full type declarations rather than only as part of union types.
  • New Random extension — the Random\Randomizer class and supporting classes provide an object-oriented, pluggable API for random number and string generation, replacing scattered rand() / mt_rand() calls.
  • SensitiveParameter attribute — mark function parameters that should be redacted in stack traces, preventing credentials or tokens from appearing in error logs.
  • Deprecated: dynamic properties — setting an undeclared property on a class now emits a deprecation notice unless the class is annotated with #[AllowDynamicProperties]. This affects some older WordPress plugins that set arbitrary properties on objects.
  • Deprecated: ${var} string interpolation — the ${var} and ${expr} interpolation syntaxes are deprecated in favour of {$var}.

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 provides all PHP versions from 7.4 through 8.5 for Ubuntu, updated alongside official PHP releases. Ubuntu’s default repositories lag behind official releases, so the PPA is required for PHP 8.2 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.2 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.2 \
  php8.2-common \
  php8.2-cli \
  php8.2-fpm \
  php8.2-mysql \
  php8.2-curl \
  php8.2-opcache \
  php8.2-mbstring \
  php8.2-xml \
  php8.2-zip \
  php8.2-readline

Additional extensions commonly needed: php8.2-gd for image processing, php8.2-intl for internationalization, php8.2-redis for Redis object caching, php8.2-imagick for ImageMagick integration, php8.2-apcu for APCu user data caching. Install only what your application explicitly requires.

Switch to PHP 8.2 on Apache

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

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

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

sudo apt install libapache2-mod-php8.2

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.2 FPM socket:

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

Switch to PHP 8.2 on Nginx

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

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

sudo systemctl restart php8.2-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.2. 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.2.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 from dynamic property usage — this is the most common deprecation notice WordPress plugins trigger on PHP 8.2

Post-upgrade checks

  • Watch for dynamic property deprecation notices — PHP 8.2 emits a deprecation notice when code sets an undeclared property on a class. WordPress core handles this correctly; older plugins may not. These are warnings, not fatal errors, but suppress legitimate errors in logs if they fire at high volume
  • Review php.ini for settings that may have changed defaults in 8.2 — particularly error_reporting and display_errors
  • 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.1* (adjust the version number)

For WordPress sites, plugin compatibility with PHP 8.2 is generally good as of 2025 — most actively maintained plugins have addressed dynamic property deprecation. 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 one of the core items in the WordPress security practices checklist — PHP 8.2 enters end-of-life in December 2026, after which no further security patches are released.

Troubleshooting

Problem Solution
Extension not found or not loading Install via sudo apt install php8.2-<extension>. Confirm loaded with php -m | grep <extension>
Web server still shows old PHP version Disable old mod, enable php8.2, 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.2/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.2-fpm for the error. A missing extension or malformed php.ini entry is the usual cause

PHP 8.2 is a stable platform for WordPress and most PHP applications. When you’re ready to move to the current active release, the PHP 8.4 upgrade guide covers property hooks, asymmetric visibility, new array functions, and the full upgrade process — the steps are the same as this guide, adjusting the version number throughout.

Frequently asked questions

PHP 8.2's main additions: readonly classes — the readonly modifier can now be applied to an entire class, making all properties readonly without annotating each one individually. Disjunctive Normal Form (DNF) types allow intersection types combined with unions: (A&B)|null is valid syntax. null, true, and false can now be used as standalone type declarations rather than only inside union types. The new Random extension introduces RandomRandomizer, an object-oriented API for random number and string generation. The SensitiveParameter attribute marks function parameters that should be redacted in stack traces, preventing credentials from appearing in error logs. PHP 8.2 also deprecates dynamic properties — setting an undeclared property on a class without #[AllowDynamicProperties] now emits a deprecation notice.

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 releases. Ubuntu's default repositories lag behind official PHP releases, so the Sury PPA is required for PHP 8.2 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.2: php8.2-mysql (database connection), php8.2-curl (HTTP requests and API calls), php8.2-mbstring (multibyte string handling), php8.2-xml (XML parsing used by many plugins), php8.2-zip (plugin and theme installation), php8.2-opcache (bytecode caching — significant performance impact, always enable). Additional extensions commonly required: php8.2-gd or php8.2-imagick for image resizing in the media library, php8.2-intl for multilingual plugin support, php8.2-redis if using Redis object caching, php8.2-apcu for APCu object caching. Install via sudo apt install php8.2-.

For new deployments or servers with flexibility, upgrade directly to PHP 8.4 — it's the current active release with full bug and security fixes, and is compatible with WordPress 6.x and all actively maintained plugins. PHP 8.2 is in security-support-only mode since December 2024 and reaches end-of-life in December 2026. Upgrade to PHP 8.2 specifically if your application has a confirmed dependency that requires 8.2 but hasn't been tested on 8.4, or as an intermediate step when jumping from PHP 8.0 or 8.1 where jumping two major minor versions feels risky. The upgrade process is identical — adjust the version number throughout.

For Apache with mod_php: sudo a2dismod php8.x (disable current version), sudo a2enmod php8.2 (enable new), sudo service apache2 restart. The mod_php package is libapache2-mod-php8.2 — 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.2-fpm.sock), then sudo systemctl restart php8.2-fpm nginx. For the CLI default, run sudo update-alternatives --config php and select /usr/bin/php8.2. The web server PHP version and CLI PHP version are independent — both must be updated separately.

Four checks after upgrade: (1) verify php -v shows 8.2 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 specifically for dynamic property deprecation notices — PHP 8.2 emits these when code sets undeclared properties on objects, which some older WordPress plugins trigger; (3) confirm all required extensions are loaded with php -m | grep ; (4) run your application through critical paths — login, content editing, form submissions, checkout if applicable. Once stable for 48+ hours, remove the old PHP version with sudo apt purge php8.x* to eliminate unmaintained packages.

AK

Written by Ajay Khandal

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

Work with me →