How to Install and Configure PHP 8.2 on Ubuntu/Debian with Ondřej’s PPA

This guide explains the new features of PHP 8.2, shows how to add Ondřej Surý’s PPA on Ubuntu and Debian, provides step‑by‑step commands to install PHP 8.2 and its extensions, configure Apache or Nginx, test the installation, purge old versions, and manage multiple PHP versions side‑by‑side.

Open Source Tech Hub
Open Source Tech Hub
Open Source Tech Hub
How to Install and Configure PHP 8.2 on Ubuntu/Debian with Ondřej’s PPA

New Features in PHP 8.2

PHP 8.2 adds several language and runtime enhancements:

Read‑only classes : the readonly keyword can be applied to an entire class, making all properties immutable after construction.

Bundled random extension : provides a modern, cryptographically‑secure random number API (e.g., random_int(), random_bytes()) without requiring external libraries.

Sensitive‑parameter handling : parameters marked with #[\SensitiveParameter] are omitted from stack traces and logs.

Deprecations : dynamic properties are deprecated; certain string‑interpolation behaviours and legacy INI settings now emit warnings.

Package Sources for Debian‑based Systems

The default Debian and Ubuntu repositories do not contain PHP 8.2 packages. The recommended source is the Ondřej Surý PPA, which provides up‑to‑date PHP 8.2 binaries and PECL extensions for all supported Debian‑based releases.

Quick Installation – Ubuntu

sudo dpkg -l | grep php | tee packages.txt
sudo add-apt-repository ppa:ondrej/php   # press Enter when prompted
sudo apt update
sudo apt install php8.2 php8.2-cli php8.2-{bz2,curl,mbstring,intl}
# Choose one of the following server APIs:
#   PHP‑FPM (recommended)
sudo apt install php8.2-fpm
sudo a2enconf php8.2-fpm
#   or Apache module
# sudo apt install libapache2-mod-php8.2
#   or Nginx (install the same php8.2-fpm package)
# When upgrading from an older version:
sudo a2disconf php8.1-fpm
sudo apt purge php8.1*

Quick Installation – Debian

sudo dpkg -l | grep php | tee packages.txt
sudo apt install apt-transport-https lsb-release ca-certificates wget -y
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update
sudo apt install php8.2 php8.2-cli php8.2-{bz2,curl,mbstring,intl}
sudo apt install php8.2-fpm   # or libapache2-mod-php8.2
sudo a2enconf php8.2-fpm
# When upgrading from an older version:
sudo a2disconf php8.1-fpm
sudo apt purge php8.1*

Detailed Installation Guide

1. Record the current PHP package set

Capture the list of installed PHP packages before upgrading. This file can be used to recreate the same environment later.

dpkg -l | grep php | tee packages.txt

2. Add the Ondřej Surý PPA

After adding the repository, the standard apt workflow can be used for installation and updates.

# Ubuntu LTS
sudo add-apt-repository ppa:ondrej/php
sudo apt update

# Debian (requires HTTPS transport and CA certificates)
sudo apt install apt-transport-https lsb-release ca-certificates software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

3. Install PHP 8.2 and common extensions

All PHP 8.2 packages follow the php8.2- naming scheme. Core extensions such as json, ctype, date, and the new random extension are bundled and do not require separate installation.

sudo apt install php8.2 php8.2-cli php8.2-{curl,bz2,mbstring,intl}

4. Install and enable a server API

Apache with PHP‑FPM (recommended)

sudo apt install php8.2-fpm
sudo a2enconf php8.2-fpm
sudo service apache2 restart

Apache as a PHP module (use only for special cases)

sudo apt install libapache2-mod-php8.2
sudo a2enmod php8.2
sudo a2dismod php8.1   # when upgrading
sudo service apache2 restart

Nginx with PHP‑FPM

sudo apt install php8.2-fpm
sudo service nginx restart
# Edit the site configuration to point to the new socket:
fastcgi_pass unix:/run/php/php8.2-fpm.sock;

5. Verify the installation

php -v
php -m

The output should show PHP 8.2 and a list of enabled extensions.

6. Remove older PHP versions (optional)

sudo apt purge php8.1*

Purging removes the packages and their configuration files. It is advisable to keep older versions until the new installation has been fully tested.

Running Multiple PHP Versions Side‑by‑Side

Multiple PHP versions can coexist; each binary is installed under /usr/bin/phpX.Y .

Use update-alternatives to switch the default php command.

sudo update-alternatives --config php
# Example interactive output:
# 0  /usr/bin/php8.2  82  auto mode
# 1  /usr/bin/php8.1  81  manual mode
# 2  /usr/bin/php8.2  82  manual mode

To set a specific version without interaction:

sudo update-alternatives --set php /usr/bin/php8.1
PHP 8.2 illustration
PHP 8.2 illustration
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxPHPInstallationUbuntuDebian
Open Source Tech Hub
Written by

Open Source Tech Hub

Sharing cutting-edge internet technologies and practical AI resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.