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
readonlymodifier 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)|nullis valid, enabling more precise type declarations without custom interfaces. null,true, andfalseas standalone types — these can now be used as full type declarations rather than only as part of union types.- New
Randomextension — theRandom\Randomizerclass and supporting classes provide an object-oriented, pluggable API for random number and string generation, replacing scatteredrand()/mt_rand()calls. SensitiveParameterattribute — 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
sudoprivileges - 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_reportinganddisplay_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.


