Debian 13 moved on to PHP 8.4, while Debian 12 still ships PHP 8.2 and Debian 11 never carried it in the base archive. To install PHP 8.2 on Debian, that release split is the first thing to check: Bookworm can use the default repositories, but Trixie and Bullseye need the Sury PHP repository.
PHP 8.2 still makes sense when an application stack is pinned to that branch, but it is no longer the best starting point for brand-new deployments. Once the right repository is in place, web server setup, extensions, and cleanup all work the same way regardless of which Debian release you are running.
The commands target Debian 13, 12, and 11. PHP 8.2 receives security fixes until December 31, 2026 according to PHP’s supported versions page, so keep that end-of-life date in mind if the host needs long-term support.
Install PHP 8.2 on Debian
Update Debian Before Installing PHP 8.2
Refresh package metadata and install pending upgrades first so PHP 8.2 pulls against current libraries:
sudo apt update && sudo apt upgrade
These commands use
sudofor root privileges. If your account is not in the sudoers group yet, use the Debian guide to add a user to sudoers on Debian before continuing.
Compare PHP 8.2 Availability on Debian
The repository choice depends on your Debian release more than anything else. Debian 12 already ships PHP 8.2, while Debian 13 and Debian 11 need Sury to expose the php8.2 packages.
| Debian release | Default PHP branch | PHP 8.2 in default repo | Best path for PHP 8.2 |
|---|---|---|---|
| Debian 13 (Trixie) | 8.4.x | No | Add the Sury repository |
| Debian 12 (Bookworm) | 8.2.x | Yes | Use the default Debian repository |
| Debian 11 (Bullseye) | 7.4.x | No | Add the Sury repository |
- Use the Debian 12 default repository if you only need PHP 8.2 and want Debian-managed updates.
- Use Sury on Debian 13 or Debian 11 because
php8.2is not available in those default archives. - Use Apache mod_php for the shortest Apache-only setup.
- Use PHP-FPM for Nginx or when you want better process isolation and easier multi-version hosting.
If you are not locked to PHP 8.2 for application compatibility, newer branches are the better long-term pick. See PHP 8.4 on Debian or PHP 8.5 on Debian instead.
Use Debian 12 Default Repositories for PHP 8.2
Bookworm is the simplest case because PHP 8.2 already lives in the default Debian archive. Confirm that APT sees the package from Debian’s default sources:
apt-cache policy php8.2
php8.2:
Installed: (none)
Candidate: 8.2.31-1~deb12u1
Version table:
8.2.31-1~deb12u1 500
500 http://deb.debian.org/debian bookworm/main amd64 Packages
500 http://security.debian.org/debian-security bookworm-security/main amd64 Packages
If your output looks like this, skip the Sury repository setup and choose the matching Apache or Nginx setup after the repository check. Debian 12 users only need Sury when they also want newer PHP branches like 8.3, 8.4, or 8.5 on the same host.
Add the Sury Repository for PHP 8.2 on Debian 13 and Debian 11
Trixie and Bullseye need an external repository for PHP 8.2. This manual DEB822 setup uses Sury’s current signing key, keeps the key scoped to the PHP source, and avoids the extrepo conflict problems that show up on newer APT releases.
Use only one Sury setup path. If this system already enabled the Sury PHP repository through extrepo on Debian, remove that older source before adding the manual DEB822 file at
/etc/apt/sources.list.d/php.sources. Both methods point to the same repository with differentSigned-Bypaths, and newer APT releases reject the duplicate configuration.
Install the packages needed to download the key and repository metadata:
sudo apt install ca-certificates curl
Download Sury’s binary keyring, install it into Debian’s shared keyring path, then remove the temporary copy:
curl -fsSLo /tmp/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
sudo install -m 0644 /tmp/deb.sury.org-php.gpg /usr/share/keyrings/deb.sury.org-php.gpg
rm -f /tmp/deb.sury.org-php.gpg
Create the DEB822 repository file using your Debian codename and architecture. Sury currently publishes PHP 8.2 packages for Debian 13, 12, and 11 on amd64, arm64, and armhf:
. /etc/os-release
ARCH=$(dpkg --print-architecture)
case "${VERSION_CODENAME}:${ARCH}" in
trixie:amd64|trixie:arm64|trixie:armhf|bookworm:amd64|bookworm:arm64|bookworm:armhf|bullseye:amd64|bullseye:arm64|bullseye: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 'This Sury PHP 8.2 method currently supports Debian 13, 12, or 11 on amd64, arm64, or armhf.\n' >&2
false
;;
esac
Refresh APT metadata and verify that php8.2 now comes from Sury:
sudo apt update
apt-cache policy php8.2
APT should show the Sury source during the refresh:
Get:5 https://packages.sury.org/php trixie InRelease [6,126 B] Get:6 https://packages.sury.org/php trixie/main amd64 Packages [275 kB]
php8.2:
Installed: (none)
Candidate: 8.2.31-3+0~20260514.89+debian13~1.gbpa1fd89
Version table:
8.2.31-3+0~20260514.89+debian13~1.gbpa1fd89 500
500 https://packages.sury.org/php trixie/main amd64 Packages
On Debian 11, the suite changes to
bullseyeand the package suffix changes todebian11. Sury can also provide dependency builds required by its PHP packages, so keep this source enabled while Sury-managed PHP packages remain installed. Debian 12 can use the same Sury setup when you need PHP 8.2 alongside newer PHP branches, but Bookworm does not require it for a straight PHP 8.2 install.
Compare PHP 8.2 Web Server Setups on Debian
Once the repository side is sorted out, choose the PHP handler that matches your web stack:
| Setup | Best for | Multiple PHP versions | Notes |
|---|---|---|---|
| Apache + mod_php | Simple Apache-only sites | No | Lowest setup friction, but PHP runs inside Apache workers |
| Apache + PHP-FPM | Production Apache hosts | Yes | Cleaner process separation and easier pool-based tuning |
| Nginx + PHP-FPM | Nginx, reverse proxies, busier sites | Yes | Required for Nginx because there is no Nginx mod_php module |
Use PHP-FPM unless you specifically want the shortest Apache setup. It is the better fit for Nginx, and it keeps PHP version switching cleaner on shared hosts.
- Use Apache mod_php when one Apache site needs one PHP branch and you want the fewest moving parts.
- Use Apache plus PHP-FPM when the server already runs Apache but different projects need different PHP branches.
- Use Nginx plus PHP-FPM when the host is already standardized on Nginx or when you want the cleanest FastCGI layout.
Install PHP 8.2 with Apache mod_php on Debian
This path assumes Apache on Debian is already installed. Add the PHP 8.2 Apache module and the base runtime packages with:
sudo apt install php8.2-cli libapache2-mod-php8.2
If Apache was already running, restart it so the new module is loaded into the active worker processes:
sudo systemctl restart apache2
Verify that the CLI binary is available and Apache loaded the PHP module:
php8.2 --version
sudo a2query -m php8.2
PHP 8.2.31 (cli) (built: May 8 2026 07:20:38) (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
php8.2 (enabled by maintainer script)
Install PHP 8.2 with Apache and PHP-FPM on Debian
This is the better Apache option when you want PHP isolated from Apache worker processes. Install PHP-FPM and the CLI package:
sudo apt install php8.2-cli php8.2-fpm
If
libapache2-mod-php8.2is already active, disable it before switching to PHP-FPM:sudo a2dismod php8.2. Apache should use one PHP handler at a time.
The php8.2-fpm package ships the Apache configuration file for this proxy_fcgi setup, so libapache2-mod-fcgid is not required. Enable the required Apache modules and the PHP-FPM configuration, then start the service:
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.2-fpm
sudo systemctl enable php8.2-fpm --now
sudo systemctl restart apache2
Confirm that PHP-FPM is running and ready to accept connections:
systemctl is-active php8.2-fpm
active
The default PHP-FPM socket path is /run/php/php8.2-fpm.sock. Confirm that it exists before pointing Apache or Nginx at it:
ls -l /run/php/php8.2-fpm.sock
srw-rw---- 1 www-data www-data 0 May 22 10:35 /run/php/php8.2-fpm.sock
Install PHP 8.2 with Nginx and PHP-FPM on Debian
This path assumes Nginx on Debian is already installed. Install the PHP 8.2 runtime and FPM service, then enable it:
sudo apt install php8.2-cli php8.2-fpm
sudo systemctl enable php8.2-fpm --now
Point your Nginx server block at the PHP 8.2 socket. The package-created socket path is /run/php/php8.2-fpm.sock:
server {
listen 8080;
server_name _;
root /var/www/php82test;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
}
Test the Nginx configuration before reloading the service:
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Reload Nginx after the syntax test passes:
sudo systemctl reload nginx
Install PHP 8.2 Extensions on Debian
Install Common PHP 8.2 Extensions on Debian
Most web applications need more than the base runtime. This package set covers database access, image handling, archives, string handling, caching, and XML processing:
sudo apt install php8.2-{curl,mysql,gd,opcache,zip,intl,bcmath,imagick,redis,memcached,mbstring,apcu,xml,soap}
The php8.2-mysql package gives PHP access to MySQL 8.0 on Debian and MariaDB on Debian. If you need ImageMagick integration beyond the standard package install, the separate PHP Imagick on Debian guide covers that workflow in more detail.
JSON support is built into PHP 8.2, so there is no separate
php8.2-jsonpackage. If you maintain older software that still needs XML-RPC, install the optionalphp8.2-xmlrpcpackage separately and addxmlrpcto your module check after installation.
Verify that the extensions you care about are loaded:
php8.2 -m | grep -E '^(apcu|curl|gd|imagick|intl|mbstring|memcached|mysqli|redis|soap|xml|zip)$'
apcu curl gd imagick intl mbstring memcached mysqli redis soap xml zip
Install PHP 8.2 Development Packages on Debian
For PECL builds, extension compilation, or code coverage in test suites, add the PHP 8.2 development packages:
sudo apt install php8.2-dev php8.2-pcov
php8.2-dev provides phpize and the header files needed for extension builds, while php8.2-pcov is a lightweight coverage driver for development and CI jobs.
Manage PHP 8.2 on Debian
Update PHP 8.2 Packages on Debian
Debian 12 archive packages and Sury PHP packages both update through APT. On Debian 13 or Debian 11, keep the Sury repository enabled while PHP 8.2 from Sury remains installed so package updates and dependency fixes continue to resolve cleanly.
sudo apt update
sudo apt upgrade
After an update, confirm the active PHP 8.2 branch:
php8.2 --version
PHP 8.2.31 (cli) (built: May 8 2026 07:20:38) (NTS)
Switch the Default PHP CLI Version on Debian
If the same host also has newer PHP branches installed, Debian’s alternatives system decides what the plain php command launches. Check the current state first:
update-alternatives --display php
php - manual mode link best version is /usr/bin/php8.4 link currently points to /usr/bin/php8.2 link php is /usr/bin/php slave php.1.gz is /usr/share/man/man1/php.1.gz /usr/bin/php8.2 - priority 82 slave php.1.gz: /usr/share/man/man1/php8.2.1.gz /usr/bin/php8.4 - priority 84 slave php.1.gz: /usr/share/man/man1/php8.4.1.gz
Set PHP 8.2 as the CLI default with:
sudo update-alternatives --set php /usr/bin/php8.2
update-alternatives: using /usr/bin/php8.2 to provide /usr/bin/php (php) in manual mode
Find PHP 8.2 php.ini Files on Debian
Debian keeps separate configuration trees for the CLI, Apache module, and PHP-FPM. The paths that exist depend on which handler packages you installed. List the active PHP 8.2 php.ini files with:
find /etc/php/8.2 -type f -name php.ini -print | sort
/etc/php/8.2/cli/php.ini /etc/php/8.2/fpm/php.ini
Use /etc/php/8.2/cli/php.ini for shell commands and /etc/php/8.2/fpm/php.ini for PHP-FPM behind Apache or Nginx. If you installed libapache2-mod-php8.2, Apache mod_php uses /etc/php/8.2/apache2/php.ini.
Troubleshoot PHP 8.2 on Debian
Fix “Unable to Locate Package php8.2” on Debian
This error means APT cannot see a repository that provides the php8.2 package:
E: Unable to locate package php8.2 E: Couldn't find any package by glob 'php8.2'
Check what PHP branch your current Debian release exposes by default:
apt-cache policy php
php:
Installed: (none)
Candidate: 2:7.4+76
Version table:
2:7.4+76 500
500 http://deb.debian.org/debian bullseye/main amd64 Packages
On Debian 11 and Debian 13, that output tells you the default archive is on a different PHP branch. Add the Sury repository, run sudo apt update, and confirm that apt-cache policy php8.2 shows a Sury candidate before installing.
Fix a Missing PHP 8.2 FPM Socket on Debian
Nginx and Apache proxy_fcgi setups use the PHP-FPM socket at /run/php/php8.2-fpm.sock. If Nginx shows a 502 error or the web server log mentions a missing socket, check the service and socket together:
connect() to unix:/run/php/php8.2-fpm.sock failed (2: No such file or directory)
systemctl status php8.2-fpm --no-pager
ls -l /run/php/php8.2-fpm.sock
If the unit is missing, install php8.2-fpm. If it is installed but inactive, enable it and check the socket again:
sudo apt install php8.2-fpm
sudo systemctl enable php8.2-fpm --now
ls -l /run/php/php8.2-fpm.sock
srw-rw---- 1 www-data www-data 0 May 22 10:35 /run/php/php8.2-fpm.sock
Reload the web server only after the socket exists, then retest the PHP page or local request that failed.
Fix Sury Signed-By Conflicts from a Previous extrepo Setup on Debian
If an older Sury source file is still present with a different key path, APT stops before it refreshes packages:
Error: Conflicting values set for option Signed-By regarding source https://packages.sury.org/php/ trixie: /var/lib/extrepo/keys/sury-php.gpg != /usr/share/keyrings/deb.sury.org-php.gpg Error: The list of sources could not be read.
List every file that still references the Sury PHP repository:
grep -R "packages.sury.org/php" /etc/apt/sources.list /etc/apt/sources.list.d 2>/dev/null
/etc/apt/sources.list.d/php.sources:URIs: https://packages.sury.org/php/ /etc/apt/sources.list.d/extrepo_sury.sources:URIs: https://packages.sury.org/php/
Keep the repository file you want and remove the duplicate. If /etc/apt/sources.list.d/php.sources should remain the active Sury source, remove the older extrepo-style file and refresh APT:
sudo rm -f /etc/apt/sources.list.d/extrepo_sury.sources /var/lib/extrepo/keys/sury.asc /var/lib/extrepo/keys/sury-php.gpg
sudo apt update
A clean sudo apt update run without the conflict error confirms the duplicate source is gone. Then confirm that APT resolves php8.2 normally again:
apt-cache policy php8.2
Remove PHP 8.2 from Debian
Remove PHP 8.2 Packages on Debian
Remove only the installed PHP 8.2 branch packages. The package list step keeps shared packages such as php-common out of the removal unless APT later marks them as unused dependencies:
php82_packages=$(dpkg-query -W -f='${binary:Package}\n' 'php8.2*' 'libapache2-mod-php8.2' 2>/dev/null | grep -E '^(php8\.2($|-)|libapache2-mod-php8\.2$)' | sort -u)
if [ -n "$php82_packages" ]; then
printf '%s\n' "$php82_packages"
printf '%s\n' "$php82_packages" | xargs -r sudo apt remove --purge
else
printf 'No PHP 8.2 packages are installed.\n'
fi
Review APT’s transaction summary before accepting the removal. Then clear dependencies that APT reports as no longer required:
sudo apt autoremove
Verify that the PHP 8.2 packages are gone:
dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' 'php8.2*' 'libapache2-mod-php8.2' 2>/dev/null | grep '^ii' || echo "No PHP 8.2 packages are installed."
No PHP 8.2 packages are installed.
Remove the Sury Repository on Debian 13 and Debian 11
If you added Sury only for PHP 8.2, remove the source file and its keyring after the packages are gone. Keep the source enabled if another Sury PHP branch or Sury-provided dependency package still needs it.
sudo rm -f /etc/apt/sources.list.d/php.sources /usr/share/keyrings/deb.sury.org-php.gpg
sudo apt update
Debian 12 users who installed PHP 8.2 from the default repositories can skip this repository cleanup step.
Conclusion
PHP 8.2 can now run on Debian through Apache or Nginx, with version-specific extensions, PHP-FPM socket checks, update handling, and branch-safe removal available when the host changes later. Add Composer on Debian for dependency management, or build a full stack with WordPress with Nginx on Debian or WordPress with Apache on Debian.


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><blockquote>quote</blockquote>