How to Install PHP 8.5 on Debian 13, 12 and 11

Install PHP 8.5 on Debian 13, 12, or 11 with the Sury APT repository. Covers Apache, Nginx, PHP-FPM, extensions, updates, and removal.

Last updatedAuthorJoshua JamesRead time8 minGuide typeDebian

Debian 13 (trixie) already ships PHP 8.4.x, Debian 12 (bookworm) ships PHP 8.2.x, and Debian 11 (bullseye) stays on PHP 7.4.x in the default APT sources. That matters when you want to install PHP 8.5 on Debian for Laravel, WordPress testing, or any project that needs the pipe operator, the URI extension, and the new array helper functions covered in the official PHP 8.5 release announcement.

Ondrej Sury’s third-party APT repository provides PHP 8.5 packages for all three Debian releases and keeps branches co-installable, so PHP 8.4 and PHP 8.5 can share the same host during staged upgrades. PHP 8.5 remains in active support through December 2027 and receives security fixes through December 2029 according to the official PHP supported versions table.

Install PHP 8.5 on Debian

All supported Debian releases need the Sury repository for php8.5. If you prefer the distro branch instead, install the default PHP on Debian or install PHP 8.4 on Debian instead of adding a third-party source.

Debian ReleaseDefault PHP BranchPHP 8.5 Source
Debian 13 trixiePHP 8.4 from DebianSury repository
Debian 12 bookwormPHP 8.2 from DebianSury repository
Debian 11 bullseyePHP 7.4 from DebianSury repository

Refresh APT before adding the PHP 8.5 repository on Debian

Start with a fresh package index, then confirm which Debian codename the host is using before you add the Sury source.

sudo apt update
grep '^VERSION_CODENAME=' /etc/os-release

These commands use sudo for package-management tasks that need root privileges. If your account does not have sudo access yet, follow the guide on how to add a user to sudoers on Debian.

VERSION_CODENAME=bookworm

The codename tells you which Sury suite to use next: trixie, bookworm, or bullseye.

Add the Sury PHP repository on Debian

The manual DEB822 method is the current Debian-safe path for Sury. It works on Debian 13, Debian 12, and Debian 11 without depending on an older extrepo setup.

If you used an older extrepo-based Sury setup, remove /etc/apt/sources.list.d/extrepo_sury.sources and /var/lib/extrepo/keys/sury.asc before you continue. APT rejects duplicate Sury entries when the Signed-By paths do not match.

Install the prerequisite packages, then download the Sury key and place it in Debian’s system keyring path. Most server and minimal Debian installs need these packages even when a fuller desktop image already has them. The curl command in Linux guide breaks down the -fsSLo flags if you want to adapt the download pattern later.

sudo apt install ca-certificates curl
curl -fsSLo deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
sudo install -m 0644 deb.sury.org-php.gpg /usr/share/keyrings/deb.sury.org-php.gpg
rm -f deb.sury.org-php.gpg

This keeps the network download unprivileged and uses install only for the root-owned destination path.

Load Debian’s release metadata in the current shell and keep using the same terminal for the next command.

. /etc/os-release
printf 'Using suite: %s\n' "$VERSION_CODENAME"
Using suite: bookworm

Create the DEB822 source file next. The printf | sudo tee pattern writes the file as root more reliably than a heredoc when readers copy it from WordPress into a terminal.

case "$VERSION_CODENAME" in
trixie | bookworm | bullseye)
  printf '%s\n' \
    "Types: deb" \
    "URIs: https://packages.sury.org/php/" \
    "Suites: $VERSION_CODENAME" \
    "Components: main" \
    "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 setup supports Debian trixie, bookworm, or bullseye.\n' >&2
  ;;
esac

If the block prints the unsupported-release message, stop here. The remaining PHP 8.5 package commands are written for Debian 13 trixie, Debian 12 bookworm, and Debian 11 bullseye.

Refresh APT again and confirm that php8.5 now comes from Sury.

sudo apt update
apt-cache policy php8.5
Hit:1 http://deb.debian.org/debian bookworm InRelease
Hit:2 http://deb.debian.org/debian bookworm-updates InRelease
Hit:3 http://security.debian.org/debian-security bookworm-security InRelease
Hit:4 https://packages.sury.org/php bookworm InRelease
Reading package lists...

php8.5:
  Installed: (none)
  Candidate: 8.5.6-3+0~20260514.18+debian12~1.gbpe4e1f6
  Version table:
     8.5.6-3+0~20260514.18+debian12~1.gbpe4e1f6 500
        500 https://packages.sury.org/php bookworm/main amd64 Packages

The suite and revision string change with your Debian release. On Debian 13, the same check shows debian13 with trixie. On Debian 11, it shows debian11 with bullseye.

Review APT’s proposed transaction before you confirm later install commands. On systems that already have unversioned packages such as php-cli, php-fpm, or php-mysql, enabling Sury can make those metapackages follow Sury’s default PHP branch even when you install branch-specific php8.5-* packages.

If the host already has PHP installed, list unversioned PHP metapackages before choosing a PHP 8.5 install method.

dpkg-query -W -f='${binary:Package} ${Version}\n' 'php' 'php-*' 2>/dev/null | grep -E '^php([[:space:]]|-)' || true

Compare PHP 8.5 web server setups on Debian

Choose the integration that matches the web stack you are actually running. If the server layer is not in place yet, start with Install Apache on Debian or Install Nginx on Debian first.

MethodPackagesBest forTrade-off
Apache with mod_phpapache2, libapache2-mod-php8.5Short-lived lab stacks and simple local developmentApache switches to the prefork MPM
Apache with PHP-FPMapache2, php8.5-fpmProduction Apache servers that need separate PHP worker poolsRequires Apache proxy modules and FPM configuration
Nginx with PHP-FPMnginx, php8.5-fpm, php8.5-cliProduction Nginx deployments and LEMP stacksNginx needs a FastCGI block that points at the right socket
  • Use Apache with mod_php when you want the shortest path to a working local PHP stack.
  • Use Apache with PHP-FPM when you want Apache in front but still need cleaner process separation.
  • Use Nginx with PHP-FPM when the host already runs Nginx or you plan to build a LEMP stack for Install WordPress with Nginx on Debian.

Install PHP 8.5 with Apache mod_php on Debian

This path suits smaller Apache deployments where simplicity matters more than process isolation.

sudo apt install apache2 libapache2-mod-php8.5
sudo systemctl restart apache2

Installing libapache2-mod-php8.5 enables the PHP module automatically. Debian commonly keeps /usr/sbin outside an unprivileged shell’s default PATH, so the full apache2ctl path makes the verification command more reliable.

sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep php
php_module (shared)

Install PHP 8.5 with Apache and PHP-FPM on Debian

This setup keeps Apache in front while handing PHP requests to a separate FPM service.

sudo apt install apache2 php8.5-fpm
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.5-fpm
sudo systemctl enable php8.5-fpm --now
sudo systemctl restart apache2

If you previously tested libapache2-mod-php8.5 on the same host, disable it before you enable the FPM configuration with sudo a2dismod php8.5.

The php8.5-fpm package provides the php8.5-fpm service and the /run/php/php8.5-fpm.sock socket used by both Apache and Nginx. The Apache proxy_fcgi module comes from the Apache package itself; libapache2-mod-fcgid is not needed for this handoff.

systemctl is-active php8.5-fpm
ls -l /run/php/php8.5-fpm.sock
sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep proxy_fcgi
sudo /usr/sbin/a2query -c php8.5-fpm
active
srw-rw---- 1 www-data www-data 0 Mar 14 09:24 /run/php/php8.5-fpm.sock
proxy_fcgi_module (shared)
php8.5-fpm (enabled by site administrator)

Install PHP 8.5 with Nginx and PHP-FPM on Debian

Nginx always uses PHP-FPM for PHP requests, so this path installs the FPM service and the CLI tools together. For a broader explanation of FastCGI parameters and socket placement, see how to configure Nginx with PHP-FPM.

sudo apt install nginx php8.5-fpm php8.5-cli
sudo systemctl enable php8.5-fpm --now

Add this location block to the relevant server block so Nginx passes PHP requests to the PHP 8.5 socket.

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.5-fpm.sock;
}

Check the service state, confirm that the socket exists, then test the Nginx configuration before you reload it.

systemctl is-active php8.5-fpm
ls -l /run/php/php8.5-fpm.sock
sudo nginx -t
active
srw-rw---- 1 www-data www-data 0 Mar 14 09:24 /run/php/php8.5-fpm.sock
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Once the syntax check passes, reload Nginx to pick up the change.

sudo systemctl reload nginx

Verify the PHP 8.5 CLI on Debian

Confirm the branch-specific interpreter before you move on to extensions or application setup. Use php8.5 here because the plain php command may still point to Debian’s default branch until you change alternatives.

php8.5 --version
PHP 8.5.6 (cli) (built: May 14 2026 15:46:20) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.5.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.6, Copyright (c), by Zend Technologies

Install PHP 8.5 extensions on Debian

Most PHP applications need extra modules beyond the base interpreter. This extension set covers the usual requirements for WordPress, Laravel, API clients, database access, image handling, caching, and debugging.

Install common PHP 8.5 extensions on Debian

Install the modules that match the application you are building. php8.5-mysql provides both mysqli and pdo_mysql, while php8.5-xml bundles DOM, XMLReader, and XMLWriter support.

sudo apt install php8.5-curl php8.5-mysql php8.5-gd php8.5-zip php8.5-intl php8.5-bcmath php8.5-imagick php8.5-xmlrpc php8.5-readline php8.5-memcached php8.5-redis php8.5-mbstring php8.5-apcu php8.5-xml php8.5-xdebug php8.5-soap

There is no separate php8.5-opcache package in Sury. Zend OPcache ships with php8.5-common, which the base PHP packages already install. JSON support is also built into PHP 8.x, so you do not need a php8.5-json package either.

Restart PHP-FPM after adding extensions when Apache or Nginx serves PHP through PHP-FPM.

sudo systemctl restart php8.5-fpm

For Apache mod_php sites, restart Apache instead.

sudo systemctl restart apache2

Verify a few commonly needed modules, then confirm that Zend OPcache is active in the CLI build.

php8.5 -m | grep -E 'curl|gd|mbstring|mysqli|xml$'
php8.5 --version | grep 'Zend OPcache'
curl
gd
mbstring
mysqli
xml
    with Zend OPcache v8.5.6, Copyright (c), by Zend Technologies

For a fuller application stack, pair PHP 8.5 with Install WordPress with Apache on Debian or Install WordPress with Nginx on Debian after the required modules are in place. If image processing is the main missing piece, the PHP Imagick on Debian guide covers that extension in more depth.

Search available PHP 8.5 extensions on Debian

Use the package cache when you need a module that is not in the common list.

apt-cache search '^php8.5-' | sed -n '1,12p'
libapache2-mod-php8.5 - server-side, HTML-embedded scripting language (Apache 2 module)
libphp8.5-embed - HTML-embedded scripting language (Embedded SAPI library)
php8.5-amqp - AMQP extension for PHP
php8.5-apcu - APC User Cache for PHP
php8.5-ast - AST extension for PHP 7
php8.5-bcmath - Bcmath module for PHP
php8.5-bz2 - bzip2 module for PHP
php8.5-calendar - calendar module for PHP
php8.5-curl - CURL module for PHP
php8.5-dba - DBA module for PHP
php8.5-decimal - arbitrary precision decimal arithmetic for PHP
php8.5-dev - Files for PHP8.5 module development

Run multiple PHP versions on Debian

Sury packages each PHP branch independently, so PHP 8.4 and PHP 8.5 can stay installed together on the same host. That is useful when you need one branch for a production application and another for testing or upgrade work.

Check the PHP CLI default with update-alternatives on Debian

Use Debian’s alternatives system to see which PHP binary the plain php command will launch. Debian 13 systems with the default PHP stack can prefer /usr/bin/php.default, so do not assume installing PHP 8.5 changes the unversioned command.

sudo update-alternatives --query php
Name: php
Link: /usr/bin/php
Slaves:
 php.1.gz /usr/share/man/man1/php.1.gz
Status: auto
Best: /usr/bin/php.default
Value: /usr/bin/php.default

Alternative: /usr/bin/php.default
Priority: 100

Alternative: /usr/bin/php8.4
Priority: 84

Alternative: /usr/bin/php8.5
Priority: 85

Set PHP 8.5 explicitly if you want the unversioned php command to run the new branch.

sudo update-alternatives --set php /usr/bin/php8.5

Retest the unversioned command after the switch.

php --version | head -n 1
PHP 8.5.6 (cli) (built: May 14 2026 15:46:20) (NTS)

Switch Apache from PHP 8.4 to PHP 8.5 on Debian

For mod_php, disable the old module first, then enable the new branch and restart Apache.

sudo a2dismod php8.4
sudo a2enmod php8.5
sudo systemctl restart apache2
sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep php
php_module (shared)

Switch Apache PHP-FPM from PHP 8.4 to PHP 8.5 on Debian

Apache with PHP-FPM switches branches by changing the enabled FPM configuration file instead of loading a PHP module.

sudo a2disconf php8.4-fpm
sudo a2enconf php8.5-fpm
sudo systemctl restart apache2
sudo /usr/sbin/a2query -c php8.5-fpm
php8.5-fpm (enabled by site administrator)

Switch Nginx from PHP 8.4 to PHP 8.5 on Debian

Nginx only needs the FastCGI socket path updated, followed by a syntax test and reload.

# Old branch
fastcgi_pass unix:/run/php/php8.4-fpm.sock;

# New branch
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
sudo nginx -t
sudo systemctl reload nginx
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Update PHP 8.5 on Debian

PHP 8.5 updates arrive through APT while the Sury source remains enabled. Preview available branch updates first, then upgrade the installed PHP 8.5 packages you actually use.

sudo apt update
apt list --upgradable 'php8.5*' 'libapache2-mod-php8.5'

Build the package list from the installed PHP 8.5 package set, including the Apache module if present. The upgrade stays interactive so you can review any dependency changes before confirming.

dpkg-query -W -f='${binary:Package}\n' 'php8.5*' 'libapache2-mod-php8.5' 2>/dev/null | grep -E '^(php8\.5($|-)|libapache2-mod-php8\.5$)' | xargs -r sudo apt install --only-upgrade

Restart PHP-FPM after updates when Apache or Nginx serves PHP through PHP-FPM.

sudo systemctl restart php8.5-fpm

For Apache mod_php hosts, restart Apache instead.

sudo systemctl restart apache2

Remove PHP 8.5 from Debian

Remove PHP 8.5 packages on Debian

List the installed PHP 8.5 packages first, including the Apache module when that method was used.

dpkg-query -W -f='${binary:Package}\n' 'php8.5*' 'libapache2-mod-php8.5' 2>/dev/null | grep -E '^(php8\.5($|-)|libapache2-mod-php8\.5$)' || true

Purge only the packages from that list, then review any now-unused dependencies before removing them.

dpkg-query -W -f='${binary:Package}\n' 'php8.5*' 'libapache2-mod-php8.5' 2>/dev/null | grep -E '^(php8\.5($|-)|libapache2-mod-php8\.5$)' | xargs -r sudo apt purge
sudo apt autoremove

Check for installed or residual PHP 8.5 package records after the purge finishes.

dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' 'php8.5*' 'libapache2-mod-php8.5' 2>/dev/null | grep -E '^(ii|rc)' || true

No output means the installed and residual PHP 8.5 package records are gone.

Remove the Sury repository from Debian

Delete the manual source file only when no other PHP branch or Sury-managed package on the host needs Sury updates. If PHP 8.4, PHP 8.3, unversioned PHP metapackages, or Sury-upgraded dependencies remain installed, keep the repository enabled until you intentionally remove or downgrade them.

Check for remaining installed packages with Sury-style Debian version strings before removing the source. Continue only when this command prints no package names.

dpkg-query -W -f='${binary:Package} ${Version}\n' | grep -E '\+0~.*\+debian(11|12|13)~' || true
sudo rm -f /etc/apt/sources.list.d/php.sources
sudo apt update
remaining_sury_refs=$(sudo find /etc/apt/sources.list /etc/apt/sources.list.d -type f -print0 2>/dev/null | sudo xargs -0 -r grep -l 'deb.sury.org-php.gpg' || true)
if [ -z "$remaining_sury_refs" ]; then
  sudo rm -f /usr/share/keyrings/deb.sury.org-php.gpg
fi
apt-cache policy php | sed -n '1,6p'
php:
  Installed: (none)
  Candidate: 2:8.4+96
  Version table:
     2:8.4+96 500
        500 http://deb.debian.org/debian trixie/main amd64 Packages

On Debian 12, the same check falls back to 2:8.2+93. On Debian 11, it falls back to 2:7.4+76 from the default Debian sources.

Troubleshoot PHP 8.5 on Debian

Resolve a Signed-By conflict from an older extrepo setup

If you previously enabled Sury with extrepo and then add the manual php.sources file from the Sury repository section, APT stops because both source files point to the same repository with different key paths.

sudo apt update
Error: Conflicting values set for option Signed-By regarding source https://packages.sury.org/php/ trixie: /var/lib/extrepo/keys/sury.asc != /usr/share/keyrings/deb.sury.org-php.gpg
Error: The list of sources could not be read.

Remove the old extrepo source and key, then refresh APT before you continue with the manual Sury configuration.

sudo rm -f /etc/apt/sources.list.d/extrepo_sury.sources /var/lib/extrepo/keys/sury.asc
sudo apt update
Hit:1 http://security.debian.org/debian-security trixie-security InRelease
Hit:2 http://deb.debian.org/debian trixie InRelease
Hit:3 http://deb.debian.org/debian trixie-updates InRelease
Hit:4 https://packages.sury.org/php trixie InRelease
Reading package lists...

Fix the php8.5-fpm socket not found error on Debian

Nginx returns a 502 error when the PHP-FPM service is stopped or when the FastCGI socket path does not match the running branch.

ls -l /run/php/php8.5-fpm.sock
systemctl is-active php8.5-fpm
srw-rw---- 1 www-data www-data 0 Mar 14 09:24 /run/php/php8.5-fpm.sock
active

If the socket is missing or the service is inactive, start PHP-FPM again and retest Nginx.

sudo systemctl enable php8.5-fpm --now
sudo nginx -t
sudo systemctl reload nginx

Fix the unable to locate package php8.5-opcache error on Debian

This error usually appears because readers expect OPcache to be split into its own package. Sury does not publish a separate php8.5-opcache package, so APT cannot find it.

sudo apt install php8.5-opcache
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package php8.5-opcache
E: Couldn't find any package by glob 'php8.5-opcache'
E: Couldn't find any package by regex 'php8.5-opcache'

Check the base package candidates instead. If php8.5 and php8.5-common appear, OPcache comes with the normal PHP install.

apt-cache policy php8.5 php8.5-common | sed -n '1,12p'
php8.5:
  Installed: (none)
  Candidate: 8.5.6-3+0~20260514.18+debian12~1.gbpe4e1f6
  Version table:
     8.5.6-3+0~20260514.18+debian12~1.gbpe4e1f6 500
        500 https://packages.sury.org/php bookworm/main amd64 Packages
php8.5-common:
  Installed: (none)
  Candidate: 8.5.6-3+0~20260514.18+debian12~1.gbpe4e1f6

Install php8.5 or php8.5-common, not php8.5-opcache. If even php8.5 is missing, go back to the Sury repository section and rerun sudo apt update.

Conclusion

PHP 8.5 on Debian fits cleanly into Apache or Nginx once the Sury repository and the right extension set are in place. From here, Install PHP Composer on Debian for dependency management, then lock down the web tier with Secure Apache with Let’s Encrypt on Debian or Secure Nginx with Let’s Encrypt on Debian before the site goes live.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show more of our fresh Linux tutorials in Top Stories and From your sources when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy 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 in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<blockquote>quote</blockquote> quote block

Got a Question or Feedback?

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

Verify before posting: