Install PHP 8.2 on Ubuntu when an application still requires the 8.2 runtime, extension ABI, or compatibility behavior before you move it to a newer PHP branch. Ubuntu 26.04 defaults to PHP 8.5, Ubuntu 24.04 defaults to PHP 8.3, and Ubuntu 22.04 defaults to PHP 8.1, so the versioned php8.2 packages come from Ondrej Sury’s third-party APT repository rather than Ubuntu’s standard repositories.
You will add the Sury source at packages.sury.org, install PHP 8.2 for Apache or Nginx, verify PHP-FPM, cover common extensions, and learn how to update or remove the branch cleanly. PHP 8.2 is in security support through December 31, 2026, according to PHP’s supported versions table, so use it for compatibility workloads rather than new projects.
Install PHP 8.2 on Ubuntu
The Sury repository currently publishes PHP 8.2 packages for Ubuntu 26.04, 24.04, and 22.04. Sury’s package indexes cover the core workflow on Ubuntu 26.04 for amd64 and arm64, plus Ubuntu 24.04 and 22.04 for amd64, arm64, and armhf. Ubuntu 20.04 reached the end of standard support in May 2025 on the Ubuntu release cycle; upgrade to a supported LTS release before using these instructions on production systems.
Compare Ubuntu PHP Defaults and PHP 8.2 Availability
| Ubuntu Release | Default PHP Branch | php8.2 in Ubuntu Repositories | PHP 8.2 Path |
|---|---|---|---|
| Ubuntu 26.04 LTS | PHP 8.5 | No | Use Sury on amd64 or arm64 |
| Ubuntu 24.04 LTS | PHP 8.3 | No | Use Sury on amd64, arm64, or armhf |
| Ubuntu 22.04 LTS | PHP 8.1 | No | Use Sury on amd64, arm64, or armhf |
| Ubuntu 20.04 LTS | PHP 7.4 | No | Upgrade to a supported LTS release first |
Refresh APT and Confirm Ubuntu Details
Start with a fresh package index, then confirm the Ubuntu codename and architecture. The Sury source block uses these values to avoid writing a repository entry for unsupported combinations.
sudo apt update
These package-management commands need sudo privileges. If your account is not allowed to use sudo yet, add the account with Add a New User to Sudoers on Ubuntu before continuing.
grep '^VERSION_CODENAME=' /etc/os-release
dpkg --print-architecture
VERSION_CODENAME=resolute amd64
Ubuntu 26.04 uses resolute, Ubuntu 24.04 uses noble, and Ubuntu 22.04 uses jammy. The repository setup uses Sury’s metadata rather than Ubuntu’s broader architecture list, because PHP branch and extension packages can vary by architecture.
Add the Sury PHP Repository on Ubuntu
Install the small prerequisite set, then save the Sury signing key as a binary keyring. The curl command in Linux guide explains the -fsSLo flags if you want to adapt this download pattern for another APT repository later.
sudo apt install -y ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
Create a DEB822 source file for the Sury PHP repository. This uses the same upstream repository and signing key, but stores the source as a DEB822 .sources file for easier auditing and cleanup.
Use this packages.sury.org source instead of the older Launchpad ppa:ondrej/php entry. If the old PPA is already enabled, remove it before trusting PHP 8.2 candidates so APT does not mix sources.
. /etc/os-release
ARCH="$(dpkg --print-architecture)"
case "$VERSION_CODENAME:$ARCH" in
resolute:amd64|resolute:arm64|noble:amd64|noble:arm64|noble:armhf|jammy:amd64|jammy:arm64|jammy:armhf)
printf '%s\n' \
'Types: deb' \
'URIs: https://packages.sury.org/php/' \
"Suites: $VERSION_CODENAME" \
'Components: main' \
"Architectures: $ARCH" \
'Signed-By: /usr/share/keyrings/deb.sury.org-php.gpg' | sudo tee /etc/apt/sources.list.d/php.sources > /dev/null
;;
*)
printf 'Supported combinations: Ubuntu 26.04 on amd64/arm64; Ubuntu 24.04/22.04 on amd64/arm64/armhf. This host reports %s/%s.\n' "$VERSION_CODENAME" "$ARCH" >&2
false
;;
esac
Refresh APT after writing the source file.
sudo apt update
Confirm that the Sury source provides the PHP 8.2 packages before installing them.
apt-cache policy php8.2 php8.2-cli php8.2-fpm
Relevant output on Ubuntu 26.04 includes:
php8.2:
Installed: (none)
Candidate: 8.2.31-3+0~20260514.89+ubuntu26.04~1.gbpa1fd89
Version table:
8.2.31-3+0~20260514.89+ubuntu26.04~1.gbpa1fd89 500
500 https://packages.sury.org/php resolute/main amd64 Packages
On Ubuntu 24.04, the candidate suffix includes ubuntu24.04 and the source line shows noble. On Ubuntu 22.04, the suffix includes ubuntu22.04 and the source line shows jammy.
Compare PHP 8.2 Web Server Setups on Ubuntu
Choose the integration that matches the web server already running on the host. If the server layer is not installed yet, start with Install Apache on Ubuntu or Install Nginx on Ubuntu first.
| Setup | Packages | Best For | Trade-off |
|---|---|---|---|
| Apache with mod_php | apache2, libapache2-mod-php8.2 | Short-lived labs and simple local development | Apache runs PHP inside its worker model |
| Apache with PHP-FPM | apache2, php8.2-fpm | Production Apache sites that need separate PHP worker pools | Requires Apache proxy and FPM configuration |
| Nginx with PHP-FPM | nginx, php8.2-fpm, php8.2-cli | LEMP stacks and high-traffic PHP sites | Nginx needs a FastCGI block that points at the PHP 8.2 socket |
PHP-FPM is the better default for production because it keeps PHP in a separate service with its own pool settings, logs, and restart path. Use mod_php only when you need the shortest Apache-only setup for a local or disposable host.
Install PHP 8.2 with Apache mod_php on Ubuntu
The mod_php path loads PHP as an Apache module. It is convenient for quick development stacks but is less flexible than PHP-FPM.
sudo apt install -y apache2 libapache2-mod-php8.2
sudo systemctl restart apache2
Confirm that Apache loaded the PHP module.
sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep php
php_module (shared)
Install PHP 8.2 with Apache and PHP-FPM on Ubuntu
This setup keeps Apache in front while PHP runs through the dedicated php8.2-fpm service. For deeper pool tuning after installation, use Configure PHP-FPM on Ubuntu.
sudo apt install -y apache2 php8.2-fpm
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.2-fpm
sudo systemctl enable php8.2-fpm --now
sudo systemctl restart apache2
If you previously tested
libapache2-mod-php8.2on the same host, disable mod_php withsudo a2dismod php8.2before enabling the FPM configuration.
Check the FPM service, socket, and Apache configuration state.
systemctl is-active php8.2-fpm
test -S /run/php/php8.2-fpm.sock && echo 'php8.2-fpm socket exists'
sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep proxy_fcgi
test -L /etc/apache2/conf-enabled/php8.2-fpm.conf && echo 'php8.2-fpm configuration enabled'
active php8.2-fpm socket exists proxy_fcgi_module (shared) php8.2-fpm configuration enabled
Install PHP 8.2 with Nginx and PHP-FPM on Ubuntu
Nginx passes PHP requests to PHP-FPM through FastCGI. Install Nginx with the PHP 8.2 FPM service and CLI package if they are not already present.
sudo apt install -y nginx php8.2-fpm php8.2-cli
sudo systemctl enable php8.2-fpm --now
Add this location block to the relevant Nginx server block so PHP requests use the PHP 8.2 FPM socket.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
Validate the Nginx configuration and confirm the PHP-FPM socket exists before reloading the service.
systemctl is-active php8.2-fpm
test -S /run/php/php8.2-fpm.sock && echo 'php8.2-fpm socket exists'
sudo nginx -t
active php8.2-fpm socket exists nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl reload nginx
Verify the PHP 8.2 CLI on Ubuntu
Confirm the installed interpreter version before moving on to extensions or application setup.
php8.2 --version
PHP 8.2.31 (cli) (built: May 14 2026 15:48:50) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.31, Copyright (c) Zend Technologies
with Zend OPcache v8.2.31, Copyright (c), by Zend Technologies
Install PHP 8.2 Extensions on Ubuntu
Most PHP applications need extra modules beyond the base interpreter. The package set here covers common requirements for WordPress, Laravel, API clients, database access, GD image handling, ZIP archives, XML processing, SOAP clients, and multibyte text.
Install Common PHP 8.2 Extensions on Ubuntu
Install the modules your application needs. The grouped package list uses PHP 8.2 packages verified across the allowed Sury suite and architecture combinations.
sudo apt install -y php8.2-curl php8.2-mysql php8.2-gd php8.2-opcache php8.2-zip php8.2-intl php8.2-bcmath php8.2-readline php8.2-mbstring php8.2-xml php8.2-soap
Check APCu before installing it. The package is available on the validated amd64 hosts, but Sury’s PHP 8.2 indexes do not publish it for every supported architecture combination.
apt-cache policy php8.2-apcu
candidate="$(apt-cache policy php8.2-apcu | awk '/Candidate:/ {print $2}')"
if [ -z "$candidate" ] || [ "$candidate" = "(none)" ]; then
printf 'php8.2-apcu is not available for this Ubuntu release and architecture.\n'
else
sudo apt install -y php8.2-apcu
fi
Current Sury PHP 8.2 Ubuntu indexes do not publish
php8.2-imagick,php8.2-redis,php8.2-memcached,php8.2-xdebug,php8.2-pcov, orphp8.2-xmlrpc. Checkapt-cache policybefore using older package lists that include those names.
Do not add php8.2-json to the install command. Current Sury PHP 8.2 Ubuntu indexes do not publish a separate JSON package, and the JSON module loads with the CLI package.
php8.2 -m | grep '^json$'
json
Restart the PHP handler after installing extensions so web requests load the new modules.
sudo systemctl restart php8.2-fpm
If the host uses Apache with mod_php instead of PHP-FPM, restart Apache with
sudo systemctl restart apache2instead.
Verify several common modules and confirm OPcache is available in the CLI build.
php8.2 -m | grep -E '^(curl|gd|mbstring|mysqli|xml)$'
php8.2 --version | grep 'Zend OPcache'
curl
gd
mbstring
mysqli
xml
with Zend OPcache v8.2.31, Copyright (c), by Zend Technologies
Search Available PHP 8.2 Extensions on Ubuntu
Search the enabled repositories when you need a less common module. Use the exact PHP branch in the query so APT does not return packages for Ubuntu’s default PHP branch instead.
apt-cache pkgnames php8.2- | sort | head -n 8
Relevant output includes package names such as:
php8.2-apcu php8.2-bcmath php8.2-bz2 php8.2-cgi php8.2-cli php8.2-common php8.2-curl php8.2-dba
Install PHP 8.2 Development Headers on Ubuntu
Install the development package only when you need headers and build tooling for compiling PECL or custom PHP extensions against PHP 8.2.
sudo apt install -y php8.2-dev
Confirm that the development helper reports the PHP 8.2 branch.
php-config8.2 --version
8.2.31
Configure PHP 8.2 Settings on Ubuntu
Locate PHP 8.2 Configuration Files on Ubuntu
PHP 8.2 maintains separate configuration files for CLI and PHP-FPM. Find the active CLI configuration path first.
php8.2 --ini | head -n 3
Configuration File (php.ini) Path: /etc/php/8.2/cli Loaded Configuration File: /etc/php/8.2/cli/php.ini Scan for additional .ini files in: /etc/php/8.2/cli/conf.d
For PHP-FPM, edit /etc/php/8.2/fpm/php.ini instead. CLI changes do not automatically change web request behavior, and PHP-FPM changes need a service restart before they apply.
Adjust Common PHP 8.2 Settings on Ubuntu
Edit the FPM configuration file for web application limits such as upload size, memory, execution time, and input variables.
sudo nano /etc/php/8.2/fpm/php.ini
; Maximum upload file size
upload_max_filesize = 64M
; Maximum POST data size, keep this at least as large as upload_max_filesize
post_max_size = 64M
; Maximum memory per script
memory_limit = 256M
; Maximum script execution time in seconds
max_execution_time = 120
; Maximum input variables
max_input_vars = 3000
Restart PHP-FPM and verify one changed value.
sudo systemctl restart php8.2-fpm
php8.2 -i | grep '^upload_max_filesize'
upload_max_filesize => 64M => 64M
Run Multiple PHP Versions on Ubuntu
Sury packages each PHP branch independently, so installing PHP 8.2 can coexist with Ubuntu’s default PHP branch and newer Sury branches. Keep web-server configuration branch-specific, especially PHP-FPM sockets and Apache module names.
Switch the Ubuntu CLI PHP Version
Use update-alternatives when the unversioned php command should point to PHP 8.2. This affects CLI usage only; it does not switch Apache modules or Nginx sockets.
sudo update-alternatives --config php
There are 2 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.5 85 auto mode 1 /usr/bin/php8.2 82 manual mode 2 /usr/bin/php8.5 85 manual mode Press <enter> to keep the current choice[*], or type selection number:
On Ubuntu 24.04 or 22.04, the non-8.2 entry normally reflects that release’s default PHP branch instead.
Set PHP 8.2 directly when you do not need the interactive selector.
sudo update-alternatives --set php /usr/bin/php8.2
php --version
Switch Apache or Nginx to PHP 8.2
Apache mod_php, Apache PHP-FPM, and Nginx PHP-FPM each switch branches in a different place. Use only the block that matches your web server setup. The Apache examples use Ubuntu 26.04’s PHP 8.5 branch as the branch you are leaving; replace 8.5 with 8.3 on Ubuntu 24.04 or 8.1 on Ubuntu 22.04.
# Apache mod_php example
sudo a2dismod php8.5
sudo a2enmod php8.2
sudo systemctl restart apache2
# Apache PHP-FPM example
sudo a2disconf php8.5-fpm
sudo a2enconf php8.2-fpm
sudo systemctl restart apache2
# Nginx PHP-FPM socket example
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
sudo nginx -t && sudo systemctl reload nginx
Compare PHP 8.2 With Other PHP Versions on Ubuntu
PHP 8.2 remains useful when an application has not completed compatibility testing for newer releases. For new deployments, choose the newest branch your application and framework support.
| PHP Version | Primary Focus | Support Status | Best For | Trade-off |
|---|---|---|---|---|
| PHP (Ubuntu Default) | Release-owned stability | Matches the Ubuntu release lifecycle | Servers that prioritize Ubuntu archive updates and fewer third-party sources | Branch varies by Ubuntu release |
| PHP 8.5 | URI extension, pipe operator, clone with properties | Active support through December 2027; security through December 2029 | New applications using the latest PHP features | Default on Ubuntu 26.04; older LTS releases need Sury |
| PHP 8.4 | Property hooks, asymmetric visibility, #[\Deprecated] | Active support through December 2026; security through December 2028 | Modern production applications moving beyond PHP 8.3 | Non-default branch; use Sury when an application requires PHP 8.4 |
| PHP 8.3 | Typed class constants, json_validate(), readonly cloning | Security-only through December 2027 | Applications already standardized on PHP 8.3 | Default on Ubuntu 24.04; older or newer releases may need branch-specific packages |
| PHP 8.2 | Readonly classes, DNF types, standalone null/false/true | Security-only through December 2026 | Legacy applications requiring PHP 8.2 compatibility | No new features; plan a migration window |
PHP 8.2 introduced readonly classes, Disjunctive Normal Form types such as (A&B)|C, standalone literal types, and the Random extension. Review the official PHP 8.2 release announcement when you need to confirm whether an application depends on a specific 8.2 feature.
Update or Remove PHP 8.2 on Ubuntu
Update PHP 8.2 Packages on Ubuntu
PHP 8.2 receives APT-managed updates from the Sury repository. Update the package index, upgrade installed PHP 8.2 packages, and restart PHP-FPM when the host uses it for web requests.
sudo apt update
sudo apt install --only-upgrade 'php8.2*' 'libapache2-mod-php8.2'
sudo systemctl restart php8.2-fpm
Skip the PHP-FPM restart on Apache mod_php-only systems and restart Apache instead.
sudo systemctl restart apache2
Confirm the branch still reports PHP 8.2 after the update.
php8.2 --version
Remove PHP 8.2 Packages from Ubuntu
Remove the PHP 8.2 branch packages while preserving other PHP versions and the repository source.
sudo apt remove 'php8.2*' 'libapache2-mod-php8.2'
Use purge only when you also want to delete PHP 8.2 configuration files under /etc/php/8.2/. Back up customized php.ini, FPM pool files, or extension configuration first.
sudo apt purge 'php8.2*' 'libapache2-mod-php8.2'
sudo apt autoremove
If you pointed the unversioned php command at PHP 8.2, return it to automatic mode after removal.
sudo update-alternatives --auto php
Remove the Sury PHP Repository from Ubuntu
Remove the Sury source and signing key only when no remaining PHP branch on the host depends on that repository for updates.
sudo rm -f /etc/apt/sources.list.d/php.sources /usr/share/keyrings/deb.sury.org-php.gpg
sudo apt update
apt-cache policy php8.2
php8.2: Installed: (none) Candidate: (none) Version table:
Troubleshoot PHP 8.2 on Ubuntu
APT Cannot Locate the PHP 8.2 Package
If APT cannot find php8.2, either the Sury source was not added, APT was not refreshed after adding it, or the host does not match one of the supported suite and architecture combinations.
Error: Unable to locate package php8.2 Error: Couldn't find any package by glob 'php8.2'
Check the release, architecture, source file, and package candidate in that order.
grep '^VERSION_CODENAME=' /etc/os-release
dpkg --print-architecture
grep -R "packages.sury.org/php" /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null
sudo apt update
apt-cache policy php8.2 php8.2-cli php8.2-fpm
A valid Sury setup should show a candidate from https://packages.sury.org/php. If the source file is missing, add the Sury source again. If the host reports Ubuntu 20.04 or an unsupported architecture, move the workload to a supported Ubuntu LTS release or use a different deployment target.
Old Ondrej PPA Source Still Appears
Older PHP 8.2 instructions used the Launchpad PPA. Remove that old source before using the Sury packages.sury.org entry, because duplicate PHP sources can cause confusing candidates or Signed-By conflicts.
grep -RE "ondrej/php|ppa.launchpadcontent.net/ondrej/php" /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null
If the old PPA appears and add-apt-repository is available, remove it and refresh APT.
sudo add-apt-repository --remove ppa:ondrej/php -y
sudo apt update
If that helper is unavailable or the file was edited manually, use Remove a PPA from Ubuntu to identify the generated source file and remove it safely.
PHP 8.2 FPM Socket Is Missing in Nginx
A 502 Bad Gateway response often means Nginx points at a socket that does not exist or PHP-FPM is not running.
sudo tail -n 5 /var/log/nginx/error.log
connect() to unix:/run/php/php8.2-fpm.sock failed (2: No such file or directory) while connecting to upstream
Check the service and socket, then start PHP-FPM if needed.
systemctl is-active php8.2-fpm
test -S /run/php/php8.2-fpm.sock && echo 'php8.2-fpm socket exists'
sudo systemctl enable php8.2-fpm --now
Retest Nginx before reloading it.
sudo nginx -t && sudo systemctl reload nginx
Wrong PHP Version Runs After Installing PHP 8.2
If php --version still shows Ubuntu’s default branch, switch only the CLI alternative. Web-server handlers need their own Apache module, Apache FPM conf, or Nginx socket change.
sudo update-alternatives --set php /usr/bin/php8.2
php --version
php8.2 --version
PHP 8.2 Extension Package Has No Candidate
Some older extension lists include package names that are not published in the current Sury PHP 8.2 Ubuntu indexes. Verify the candidate before adding an optional extension to an automation script.
apt-cache policy php8.2-imagick php8.2-redis php8.2-memcached php8.2-xdebug php8.2-pcov php8.2-xmlrpc
An absent stanza or Candidate: (none) means APT cannot install that PHP 8.2 package from the enabled sources. Remove the unavailable name from the install command, use a package that exists for your PHP branch, or run the workload on a branch where the required extension is packaged.
PHP 8.2 Documentation and Reference Links
- PHP official website: Project overview, downloads, and language resources.
- PHP 8.2 release announcement: Feature highlights and migration notes for the 8.2 branch.
- PHP 8.2 changelog: Detailed point-release changes and security fixes.
- PHP documentation: Core language, extension, and configuration references.
- PHP supported versions: Current active-support and security-support dates.
Conclusion
PHP 8.2 is now installed from Sury’s APT repository with a verified Apache or Nginx path, branch-specific extension handling, and a clean update and removal plan. For next steps, deploy WordPress with Nginx and MariaDB on Ubuntu, set up phpMyAdmin with LEMP on Ubuntu, or tune Nginx FastCGI cache on Ubuntu.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><a href="https://example.com">link</a><blockquote>quote</blockquote>