How to Install PHP 8.2 on Debian (13, 12, 11)

Last updated Wednesday, March 4, 2026 4:42 pm Joshua James 10 min read

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.

These steps cover 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 sudo for 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 releaseDefault PHP branchPHP 8.2 in default repoBest path for PHP 8.2
Debian 13 (Trixie)8.4.xNoAdd the Sury repository
Debian 12 (Bookworm)8.2.xYesUse the default Debian repository
Debian 11 (Bullseye)7.4.xNoAdd 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.2 is 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 security updates:

apt-cache policy php8.2
php8.2:
  Installed: (none)
  Candidate: 8.2.30-1~deb12u1
  Version table:
     8.2.30-1~deb12u1 500
        500 http://security.debian.org/debian-security bookworm-security/main amd64 Packages
     8.2.29-1~deb12u1 500
        500 http://deb.debian.org/debian bookworm/main amd64 Packages

If your output looks like this, skip the Sury section and move straight to the Apache or Nginx installation method below. 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 matches Debian’s current repository guidance 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, remove that older source before adding the manual DEB822 file below. Both methods point to the same repository with different Signed-By paths, 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 -y

Download Sury’s binary keyring into Debian’s standard keyring path:

sudo curl -fsSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg

Create the DEB822 repository file using your Debian codename and architecture:

CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME")
ARCH=$(dpkg --print-architecture)

cat <<EOF | sudo tee /etc/apt/sources.list.d/php.sources
Types: deb
URIs: https://packages.sury.org/php/
Suites: ${CODENAME}
Components: main
Architectures: ${ARCH}
Signed-By: /usr/share/keyrings/deb.sury.org-php.gpg
EOF

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.30-3+0~20260213.84+debian13~1.gbp445d4a
  Version table:
     8.2.30-3+0~20260213.84+debian13~1.gbp445d4a 500
        500 https://packages.sury.org/php trixie/main amd64 Packages

On Debian 11, the suite changes to bullseye and the package suffix changes to debian11. 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:

SetupBest forMultiple PHP versionsNotes
Apache + mod_phpSimple Apache-only sitesNoLowest setup friction, but PHP runs inside Apache workers
Apache + PHP-FPMProduction Apache hostsYesCleaner process separation and easier pool-based tuning
Nginx + PHP-FPMNginx, reverse proxies, busier sitesYesRequired for Nginx because there is no Nginx mod_php module

Recommendation: 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.30 (cli) (built: Feb 28 2026 07:07:34) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.30, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.30, 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 the FPM package and Apache’s FastCGI module support:

sudo apt install php8.2-cli php8.2-fpm libapache2-mod-fcgid

If libapache2-mod-php8.2 is already active, disable it before switching to PHP-FPM: sudo a2dismod php8.2. Apache should use one PHP handler at a time.

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 status php8.2-fpm --no-pager | head -n 8
● php8.2-fpm.service - The PHP 8.2 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php8.2-fpm.service; enabled; preset: enabled)
     Active: active (running) since Wed 2026-03-04 16:19:46 AWST; 8s ago
       Docs: man:php-fpm8.2(8)
   Main PID: 24087 (php-fpm8.2)
     Status: "Ready to handle connections"
      Tasks: 3 (limit: 6926)
     Memory: 9.3M

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:

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-json package. If you maintain older software that still needs XML-RPC, install it separately with sudo apt install php8.2-xmlrpc.

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

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. List the main php.ini files with:

ls /etc/php/8.2/apache2/php.ini /etc/php/8.2/cli/php.ini /etc/php/8.2/fpm/php.ini
/etc/php/8.2/apache2/php.ini
/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, /etc/php/8.2/apache2/php.ini for Apache mod_php, and /etc/php/8.2/fpm/php.ini for PHP-FPM behind Apache or Nginx.

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 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.d /etc/apt/sources.list
/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 you are following this article’s manual method, remove the older extrepo-style file and refresh APT:

sudo rm -f /etc/apt/sources.list.d/extrepo_sury.sources
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 the PHP 8.2 packages and then clear any dependencies that were only installed for that branch:

sudo apt remove --purge php8.2 php8.2-cli php8.2-common php8.2-fpm php8.2-opcache php8.2-readline php-common
sudo apt autoremove
The following packages will be REMOVED:
  php-common* php8.2* php8.2-cli* php8.2-common* php8.2-fpm* php8.2-opcache*
  php8.2-readline*

Verify that the PHP 8.2 packages are gone:

dpkg -l php8.2 php8.2-cli php8.2-fpm | grep '^ii' || echo "PHP 8.2 packages are no longer installed."
PHP 8.2 packages are no longer installed.

Remove the Sury Repository on Debian 13 and Debian 11

If you added Sury for PHP 8.2, remove the source file and its keyring after the packages are gone:

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.

Frequently Asked Questions about PHP 8.2 on Debian

Is PHP 8.2 available in Debian 12 by default?

Yes. Debian 12 ships PHP 8.2 in the default repositories, so Bookworm users can install it without adding Sury.

Why does Debian 13 or Debian 11 say unable to locate package php8.2?

Because those releases do not provide php8.2 in the default archive. Add the Sury PHP repository, run apt update, and then install the package.

Where is the php.ini file for PHP 8.2 on Debian?

Debian keeps separate php.ini files by SAPI: /etc/php/8.2/cli/php.ini for the CLI, /etc/php/8.2/apache2/php.ini for Apache mod_php, and /etc/php/8.2/fpm/php.ini for PHP-FPM.

When does PHP 8.2 reach end of life?

PHP 8.2 receives security fixes until December 31, 2026 according to php.net. After that date, new security and bug-fix releases stop for the branch.

Conclusion

PHP 8.2 is handling requests on Debian through Apache or Nginx, with extensions loaded and CLI version switching ready for multi-branch hosts. Add Composer on Debian next for dependency management, or go straight to a full stack with WordPress with Nginx on Debian or WordPress with Apache on Debian.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffee Buy me a coffee

Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<a href="URL">link</a> link
<blockquote>quote</blockquote> quote block

Leave a Comment

We read and reply to every comment - let us know how we can help or improve this guide.

Let us know you are human: