Debian 13 (trixie) already ships PHP 8.4 in its default APT sources. Debian 12 (bookworm) and Debian 11 (bullseye) still need the Sury repository for the same branch. That split matters when you want to install PHP 8.4 on Debian for WordPress, Laravel, phpMyAdmin, or a custom application. PHP 8.4 adds property hooks, asymmetric visibility, and the updated HTML5 DOM API covered in the official PHP 8.4 release announcement.
On Debian 13, the working path stays inside the default APT sources. Debian 12 and Debian 11 need a manual DEB822 .sources entry for Sury instead of extrepo. Then you can choose the Apache or Nginx integration that matches your stack. PHP 8.4 remains in active support through December 2026 and receives security fixes through December 2028 according to the official PHP supported versions table.
Install PHP 8.4 on Debian
Debian 13 (trixie) ships PHP 8.4 in the default APT sources. Debian 12 (bookworm) defaults to PHP 8.2, and Debian 11 (bullseye) defaults to PHP 7.4, so those two releases need the Sury repository before the php8.4 packages appear.
Refresh APT and confirm your Debian release
Start with a fresh package index, then confirm which Debian codename you are working with.
sudo apt update
grep '^VERSION_CODENAME=' /etc/os-release
These commands use
sudofor 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 path to use next: trixie can install PHP 8.4 directly, while bookworm and bullseye need the Sury repository first.
Install PHP 8.4 from Debian 13 default APT sources
On Debian 13, check the candidate package first so you can confirm PHP 8.4 comes from Debian’s own repositories.
apt-cache policy php8.4
php8.4:
Installed: (none)
Candidate: 8.4.16-1~deb13u1
Version table:
8.4.16-1~deb13u1 500
500 http://security.debian.org/debian-security trixie-security/main amd64 Packages
8.4.11-1 500
500 http://deb.debian.org/debian trixie/main amd64 Packages
Install the core interpreter packages once the candidate looks correct.
sudo apt install -y php8.4 php8.4-cli
Verify the CLI binary before you move on to Apache or Nginx integration.
php --version
PHP 8.4.16 (cli) (built: Dec 18 2025 21:19:25) (NTS) Copyright (c) The PHP Group Built by Debian Zend Engine v4.4.16, Copyright (c) Zend Technologies
Add the Sury PHP repository on Debian 12 and Debian 11
Debian 12 and Debian 11 need the Sury repository because their default APT sources stop at older PHP branches. This workflow uses a direct key download into /usr/share/keyrings/ and a DEB822 .sources file, which matches the current Debian packaging rules better than the older extrepo path.
If you used an older
extrepo-based Sury setup, remove/etc/apt/sources.list.d/extrepo_sury.sourcesand/var/lib/extrepo/keys/sury.ascbefore adding the manualphp.sourcesfile. APT rejects duplicate Sury entries when theSigned-Bypaths do not match.
Install the prerequisites and download the repository key. Most server and minimal Debian installs need these packages even when fuller desktop images already have them. The sudo curl form writes the key directly into the root-owned keyring path, so you do not need a temporary file. If you want a refresher on the download flags, see the curl command in Linux guide.
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
Resolve your Debian codename in the current shell and keep using the same terminal for the next command.
CODENAME=$(. /etc/os-release && echo "$VERSION_CODENAME")
printf 'Using suite: %s\n' "$CODENAME"
Using suite: bookworm
Create the DEB822 source file next. The printf | sudo tee pattern is more reliable than a heredoc when readers copy the block from WordPress into a terminal.
printf '%s\n' \
"Types: deb" \
"URIs: https://packages.sury.org/php/" \
"Suites: $CODENAME" \
"Components: main" \
"Signed-By: /usr/share/keyrings/deb.sury.org-php.gpg" | sudo tee /etc/apt/sources.list.d/php.sources > /dev/null
Refresh APT again and confirm that php8.4 now comes from Sury.
sudo apt update
apt-cache policy php8.4
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.4:
Installed: (none)
Candidate: 8.4.18-2+0~20260213.42+debian12~1.gbp3e97a0
Version table:
8.4.18-2+0~20260213.42+debian12~1.gbp3e97a0 500
500 https://packages.sury.org/php bookworm/main amd64 Packages
Install the core interpreter packages after the repository check passes.
sudo apt install -y php8.4 php8.4-cli
Bookworm and bullseye use the same package names here. The only difference is the Sury suite name and the package revision string that apt-cache policy reports.
Compare PHP 8.4 web server setups on Debian
Choose the web server integration that matches the system you are actually running.
| Method | Packages | Best for | Trade-off |
|---|---|---|---|
| Apache with mod_php | apache2, libapache2-mod-php8.4 | Simple local development or smaller sites | Apache switches to the prefork MPM |
| Apache with PHP-FPM | apache2, php8.4-fpm, libapache2-mod-fcgid | Production Apache servers that need cleaner process separation | Requires Apache module and FPM config changes |
| Nginx with PHP-FPM | nginx, php8.4-fpm | Production Nginx deployments and reverse-proxy stacks | Nginx needs a FastCGI block in the server configuration |
- Use Apache with mod_php when you want the shortest path to a working local stack.
- Use Apache with PHP-FPM when you want Apache but still need separate PHP worker pools.
- Use Nginx with PHP-FPM when the site already runs on Nginx or you plan to build a LEMP stack.
These three web server paths assume you already installed the core php8.4 and php8.4-cli packages from the release-specific step above.
Install PHP 8.4 with Apache mod_php on Debian
This path suits simpler Apache deployments and lab systems where the extra isolation from PHP-FPM is not necessary.
sudo apt install -y apache2 libapache2-mod-php8.4
sudo systemctl restart apache2
Installing libapache2-mod-php8.4 automatically enables the PHP module and switches Apache from mpm_event to mpm_prefork. Use the full apache2ctl path below because Debian commonly keeps /usr/sbin outside an unprivileged SSH user’s default PATH.
sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep php
php_module (shared)
Install PHP 8.4 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 -y apache2 php8.4-fpm libapache2-mod-fcgid
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm
sudo systemctl enable php8.4-fpm --now
sudo systemctl restart apache2
If you previously tested
libapache2-mod-php8.4on the same host, disable it before you enable the FPM configuration withsudo a2dismod php8.4.
Check the service state and confirm that the PHP-FPM socket exists before you update any virtual host configuration.
systemctl is-active php8.4-fpm
ls -l /run/php/php8.4-fpm.sock
active srw-rw---- 1 www-data www-data 0 Mar 14 08:54 /run/php/php8.4-fpm.sock
Install PHP 8.4 with Nginx and PHP-FPM on Debian
Nginx always needs PHP-FPM for PHP requests, so this path is the natural fit for a LEMP server.
sudo apt install -y nginx php8.4-fpm
sudo systemctl enable php8.4-fpm --now
Add the FastCGI block below to the Nginx server block that should handle PHP files.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
}
Test the Nginx syntax before you reload 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 once the syntax check passes.
sudo systemctl reload nginx
Verify PHP 8.4 on Debian
Run one final version check after your chosen web server path is in place. The versioned php8.4 package installs the CLI binary, while the plain php command follows Debian’s alternatives system.
php --version
PHP 8.4.18 (cli) (built: Feb 13 2026 15:52:15) (NTS) Copyright (c) The PHP Group Built by Debian Zend Engine v4.4.18, Copyright (c) Zend Technologies
From here, you can continue with Install Apache on Debian, Install Nginx on Debian, Install WordPress with Apache on Debian, or Install WordPress with Nginx on Debian if you are building a full application stack.
Install PHP 8.4 extensions on Debian
Most PHP applications need more than the base interpreter. The package set below covers common framework, CMS, database, caching, and image-processing workloads, and it also fixes the missing mbstring and DOM-related errors that often appear in PHPUnit or Composer checks.
sudo apt install -y php8.4-curl php8.4-gd php8.4-mbstring php8.4-mysql php8.4-xml php8.4-zip php8.4-intl php8.4-bcmath php8.4-imagick php8.4-redis php8.4-memcached php8.4-soap php8.4-apcu
There is no separate
php8.4-jsonpackage. JSON support is built into PHP 8.x, whilephp8.4-xmlprovidesdom,xmlreader,xmlwriter, and related XML modules.
Restart the PHP handler that matches your setup after you add new modules.
# Apache with mod_php
sudo systemctl restart apache2
# Apache or Nginx with PHP-FPM
sudo systemctl restart php8.4-fpm
Check a few high-value modules before you hand the server to an application.
php8.4 -m | grep -E 'curl|gd|libxml|mbstring|mysqli|xml|xmlreader|xmlwriter'
curl gd libxml mbstring mysqli xml xmlreader xmlwriter
If you need dependency management after the runtime is ready, the next logical step is Install PHP Composer on Debian.
Update or remove PHP 8.4 on Debian
Update PHP 8.4 packages on Debian
Use a targeted APT upgrade when you only want to refresh the PHP 8.4 branch and leave unrelated packages alone.
sudo apt update
sudo apt install --only-upgrade -y php8.4 php8.4-cli
Add php8.4-fpm and any installed php8.4-* extension packages to the same command when you want to update them in one pass.
Verify the active CLI version after the upgrade finishes.
php --version
PHP 8.4.18 (cli) (built: Feb 13 2026 15:52:15) (NTS)
Remove PHP 8.4 packages on Debian
Purge the versioned packages first, then remove the dependencies that were only pulled in for PHP 8.4.
sudo apt purge -y 'php8.4*'
sudo apt autoremove --purge -y
Confirm that no installed php8.4 packages remain.
dpkg -l 'php8.4*' 2>/dev/null | grep '^ii' || echo 'No installed php8.4 packages remain.'
No installed php8.4 packages remain.
Remove the Sury repository from Debian 12 and Debian 11
Only Debian 12 and Debian 11 need this cleanup step. Debian 13 keeps PHP 8.4 in the default repositories, so there is no third-party source file to remove.
sudo rm -f /etc/apt/sources.list.d/php.sources /usr/share/keyrings/deb.sury.org-php.gpg
sudo apt update
Check the plain php package afterward to confirm APT has fallen back to Debian’s default branch.
apt-cache policy php | sed -n '1,6p'
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 12, the same check falls back to the default
2:8.2+93candidate from bookworm. On Debian 13,php8.4stays available from Debian’s own repositories even after you purge the installed packages.
Troubleshoot PHP 8.4 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 this article, APT stops because both source files point to the same repository with different key paths.
E: Conflicting values set for option Signed-By regarding source https://packages.sury.org/php/ bullseye: /var/lib/extrepo/keys/sury.asc != /usr/share/keyrings/deb.sury.org-php.gpg E: The list of sources could not be read.
Remove the old extrepo source and key, then refresh APT before you continue with the manual repository method.
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 bullseye-security InRelease Hit:2 http://deb.debian.org/debian bullseye InRelease Hit:3 https://packages.sury.org/php bullseye InRelease Reading package lists...
Fix the php8.4-fpm socket not found error on Debian
Nginx returns a 502 error when the PHP-FPM service is stopped or the socket path in the server block does not match the running FPM version.
ls -l /run/php/php8.4-fpm.sock
systemctl is-active php8.4-fpm
srw-rw---- 1 www-data www-data 0 Mar 14 08:54 /run/php/php8.4-fpm.sock active
If the socket is missing or the service is inactive, start PHP-FPM again and retest the Nginx configuration.
sudo systemctl enable php8.4-fpm --now
sudo nginx -t
sudo systemctl reload nginx
Fix the PHPUnit mbstring or DOM extension error on Debian
PHPUnit commonly fails when the CLI environment is missing mbstring or the XML modules that provide DOM support.
phpunit requires the "dom", "json", "libxml", "mbstring", "tokenizer", "xml", "xmlwriter" extensions, but the "mbstring" extension is not available.
Install the missing modules first. The php8.4-xml package covers dom, xmlreader, and xmlwriter in one step.
sudo apt install -y php8.4-mbstring php8.4-xml
php8.4 -m | grep -E 'mbstring|dom|xmlwriter'
dom mbstring xmlwriter
Fix Sury GPG key errors on Debian 12 and Debian 11
If apt update reports a missing public key, refresh the Sury keyring file and update APT again.
Err:1 https://packages.sury.org/php bookworm InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY [key-id]
Download the key again into the same keyring path, then refresh the repository metadata.
sudo curl -fsSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
sudo apt update
apt-cache policy php8.4
php8.4:
Installed: (none)
Candidate: 8.4.18-2+0~20260213.42+debian12~1.gbp3e97a0
Version table:
8.4.18-2+0~20260213.42+debian12~1.gbp3e97a0 500
500 https://packages.sury.org/php bookworm/main amd64 Packages
PHP 8.4 on Debian FAQ
Debian 13 (trixie) ships PHP 8.4 in its default APT sources. On March 14, 2026, apt-cache policy php8.4 showed 8.4.16-1~deb13u1 from trixie-security as the current candidate.
No. Debian 12 (bookworm) defaults to PHP 8.2, and Debian 11 (bullseye) defaults to PHP 7.4. You need the Sury repository if you want the PHP 8.4 branch on either release.
Install php8.4-mbstring and php8.4-xml. The php8.4-xml package provides dom, xmlreader, and xmlwriter, which are part of the common PHPUnit dependency check.
No. JSON support is built into PHP 8.x, so Debian and Sury do not ship a separate php8.4-json package. Install the other modules your application needs, such as php8.4-mbstring or php8.4-xml, but not JSON.
Conclusion
PHP 8.4 is installed on Debian with the server integration that fits your stack, whether that means Apache with mod_php, Apache with PHP-FPM, or Nginx with PHP-FPM. From here, Install PHP Composer on Debian for application dependencies, 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.
Thank you