How to Install PHP 8.4 on Debian Linux

PHP 8.4 introduces property hooks for computed properties, asymmetric visibility to control read and write access separately, the #[\Deprecated] attribute for user-defined deprecation notices, and a modern DOM API with native HTML5 parsing support. These features simplify object-oriented code patterns that previously required verbose getter/setter methods or custom validation logic. On Debian 13 (trixie), PHP 8.4 ships in the default repositories; on Debian 12 and Debian 11, you can access it through Ondřej Surý’s PHP repository.

In this guide, you will learn how to import the Sury repository where needed, install PHP 8.4 with Apache or Nginx, configure PHP-FPM for production workloads, and run multiple PHP versions side by side. By the end, you will have PHP 8.4 configured and ready to power WordPress with Apache or WordPress with Nginx, Laravel 11, or any application that benefits from property hooks and the new array functions.

Select a PHP Version for Your Debian System

Choose Between PHP 8.4, 8.3, and Distro Default

Debian repositories and the Sury repository provide different PHP versions targeting distinct use cases. Consequently, the comparison below helps you decide which release fits your project requirements and maintenance preferences.

PHP VersionPrimary FocusPerformanceBest ForTrade-offs
PHP (Distro Default)Stability with Debian security team maintenanceVaries by version; Debian 12’s PHP 8.2 includes JIT compilation and OPcacheProduction servers prioritizing official Debian updates and minimal external dependenciesVersion varies by release (8.4 on Debian 13, 8.2 on Debian 12, 7.4 on Debian 11)
PHP 8.4Property hooks, asymmetric visibility, HTML5 DOM APIContinued JIT improvements; new IR-based JIT frameworkProjects using modern OOP patterns, applications requiring array_find() and BCMath object APINewest release; requires Sury repository on Debian 11/12
PHP 8.3Typed class constants, json_validate(), readonly property cloningMature JIT optimization with broad extension compatibilityWordPress 6.x, Laravel 11, Drupal 10 sites needing stable features with security support through December 2027Requires Sury repository on all Debian versions; community-maintained updates

Recommendation: Choose PHP 8.4 when your application benefits from property hooks, asymmetric visibility, or the improved DOM API for HTML5 parsing. PHP 8.4 receives active support through December 2026 and security fixes until December 2028. However, if your application already runs well on PHP 8.3, that version remains fully supported through December 2027. For systems where you prefer official Debian security team maintenance over newer features, the distro default PHP remains a solid choice.

Explore PHP 8.4 Feature Highlights

PHP 8.4 provides tangible benefits for specific development scenarios. First, property hooks eliminate boilerplate getter and setter methods by allowing computed properties with get and set expressions directly in the property declaration. Additionally, asymmetric visibility lets you expose a property for reading (public) while restricting writes to the class itself (private(set)), thereby reducing the need for explicit accessor methods.

Furthermore, the array_find(), array_find_key(), array_any(), and array_all() functions replace common foreach patterns with expressive, single-call alternatives. Similarly, the new Dom\HTMLDocument class provides standards-compliant HTML5 parsing with CSS selector support through querySelector() and querySelectorAll(), simplifying web scraping and DOM manipulation tasks that previously required awkward workarounds.

Add the PHP 8.4 Repository on Debian

Debian 13 (Trixie) users: PHP 8.4 is available in the default Debian repositories. You can skip this entire repository section and proceed directly to “Install PHP 8.4 on Debian” using sudo apt install php8.4.

Update System Packages

First, before adding external repositories, synchronize your package index and upgrade installed packages to ensure compatibility:

sudo apt update
sudo apt upgrade

Install Repository Prerequisites

Next, install the packages required for secure repository configuration:

sudo apt install ca-certificates curl gnupg lsb-release -y

These packages handle SSL certificate validation, HTTP downloads, GPG signature verification, and distribution release detection.

Import the Ondřej Surý PHP Repository

Now, download and install the Sury repository GPG keyring package:

curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb

Then, create the repository configuration using DEB822 format:

cat <<EOF | sudo tee /etc/apt/sources.list.d/php.sources
Types: deb
URIs: https://packages.sury.org/php/
Suites: $(lsb_release -cs)
Components: main
Signed-By: /usr/share/keyrings/debsuryorg-archive-keyring.gpg
EOF

Debian 13 uses DEB822 .sources format by default. Debian 12 and 11 fully support this format, though legacy .list files remain common on older installations.

After adding the repository, refresh the package index to include the new source:

sudo apt update

Finally, confirm PHP 8.4 is available from the Sury repository:

apt-cache policy php8.4

Expected output showing the Sury repository as the package source:

php8.4:
  Installed: (none)
  Candidate: 8.4.x-1+0~20xxxxxx.xx+debian12~1.gbpxxxxx
  Version table:
     8.4.x-1+0~20xxxxxx.xx+debian12~1.gbpxxxxx 500
        500 https://packages.sury.org/php bookworm/main amd64 Packages

Version numbers and build strings change with each release. Your output will show the current version available. The codename (bookworm for Debian 12, bullseye for Debian 11) matches your Debian release.

Install PHP 8.4 on Debian

At this point, select the installation method that matches your web server configuration. Apache users can choose between mod_php (simpler setup) or PHP-FPM (better resource management). In contrast, Nginx requires PHP-FPM exclusively.

Compare Installation Methods

MethodBest ForMulti-VersionProcess Isolation
Apache mod_phpDevelopment, low-traffic sitesNo (one version per Apache instance)None (runs inside Apache)
Apache + PHP-FPMProduction, shared hostingYes (pools per version)Separate process pools
Nginx + PHP-FPMHigh-traffic productionYes (pools per version)Separate process pools

Recommendation: Choose PHP-FPM for production workloads. Specifically, the process isolation improves stability, and the pool-based architecture enables running different PHP versions for different virtual hosts simultaneously.

Option 1: Install PHP 8.4 with Apache mod_php

The mod_php approach loads PHP as an Apache module, making it suitable for development environments or smaller sites where simplicity matters more than process isolation. To begin, install the packages:

sudo apt install php8.4 libapache2-mod-php8.4

Afterward, restart Apache to activate the PHP module:

sudo systemctl restart apache2

Then, verify PHP is loaded:

php --version

Expected output:

PHP 8.4.x (cli) (built: [date]) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.x, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.x, Copyright (c), by Zend Technologies

Option 2: Install PHP 8.4 with Apache and PHP-FPM

PHP-FPM runs PHP in a separate process pool, providing better memory management and the ability to run different PHP versions for different virtual hosts. To set this up, install the required packages:

sudo apt install php8.4-fpm libapache2-mod-fcgid

If mod_php is installed from a previous configuration, disable it before enabling PHP-FPM: sudo a2dismod php8.4

Once installed, enable the required Apache modules and PHP-FPM configuration:

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.4-fpm

Enable and start PHP-FPM, then restart Apache to apply changes:

sudo systemctl enable php8.4-fpm --now
sudo systemctl restart apache2

Finally, confirm PHP-FPM is running:

sudo systemctl status php8.4-fpm

Expected output confirming active status:

● php8.4-fpm.service - The PHP 8.4 FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php8.4-fpm.service; enabled; preset: enabled)
     Active: active (running) since [date and time]
   Main PID: [pid] (php-fpm8.4)
      Tasks: [number]
     Memory: [size]
        CPU: [time]
     CGroup: /system.slice/php8.4-fpm.service

Option 3: Install PHP 8.4 with Nginx and PHP-FPM

Nginx processes PHP through FastCGI, making PHP-FPM the only option. Therefore, install the required packages:

sudo apt install php8.4 php8.4-fpm php8.4-cli

Next, enable and start PHP-FPM:

sudo systemctl enable php8.4-fpm --now

Then, verify PHP-FPM status:

sudo systemctl status php8.4-fpm

Expected output confirming active status:

● php8.4-fpm.service - The PHP 8.4 FastCGI Process Manager
     Loaded: loaded (/usr/lib/systemd/system/php8.4-fpm.service; enabled; preset: enabled)
     Active: active (running) since [date and time]

Configure Nginx Server Block for PHP-FPM

Now, add this location block to your Nginx server configuration to route PHP requests through PHP-FPM 8.4:

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

Before applying changes, test the configuration syntax:

sudo nginx -t

Expected output for valid configuration:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Once validated, apply the configuration:

sudo systemctl restart nginx

Verify PHP 8.4 Installation

Regardless of which method you chose, confirm PHP 8.4 installed correctly:

php --version

Expected output:

PHP 8.4.x (cli) (built: [date]) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.x, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.x, Copyright (c), by Zend Technologies

Install PHP 8.4 Extensions on Debian

Install Common PHP 8.4 Extensions

Most web applications require extensions beyond the base PHP installation. Accordingly, install a comprehensive set covering WordPress, Laravel, and general PHP development needs:

sudo apt install php8.4-{curl,mysql,gd,opcache,zip,intl,common,bcmath,imagick,xmlrpc,readline,memcached,redis,mbstring,apcu,xml,xdebug,soap}

JSON support is built into PHP 8.0 and later, so no separate php8.4-json package exists. The php8.4-xml package provides DOM, SimpleXML, XMLReader, and XMLWriter support. The php8.4-xdebug extension significantly impacts performance—install it only on development systems, not production servers.

After installation, restart PHP-FPM to load the new extensions:

sudo systemctl restart php8.4-fpm

Subsequently, verify the core extensions are loaded:

php8.4 -m | grep -E 'curl|mysqli|gd|mbstring|xml'

Expected output showing the extensions are active:

curl
gd
mbstring
mysqli
xml

Extension Functionality Reference

For reference, the extensions above provide these capabilities:

  • php-curl: HTTP client for API requests and remote file operations.
  • php-mysql: MySQL and MariaDB database connectivity.
  • php-gd: Image creation and manipulation (thumbnails, watermarks, captchas).
  • php-opcache: Bytecode caching to reduce PHP compilation overhead.
  • php-zip: ZIP archive creation and extraction.
  • php-intl: Internationalization including number formatting, date handling, and collation.
  • php-bcmath: Arbitrary precision mathematics, now with an object-oriented API in PHP 8.4.
  • php-imagick: Advanced image processing through ImageMagick.
  • php-xmlrpc: XML-RPC protocol support for remote procedure calls.
  • php-memcached and php-redis: Distributed caching backends for session storage and object caching. See the Redis on Debian and Memcached on Debian guides for server setup.
  • php-mbstring: Multibyte string handling for UTF-8 and international text processing.
  • php-apcu: In-memory user data cache for frequently accessed application data.
  • php-xml: XML parsing including the new Dom\HTMLDocument class for HTML5 support.
  • php-xdebug: Step debugging and profiling for development environments.
  • php-soap: SOAP web services client and server functionality.

Search Available PHP 8.4 Extensions

To explore additional options, list all available PHP 8.4 modules from the repository:

apt search php8.4-

Sample output showing available extensions:

Sorting...
Full Text Search...
php8.4-amqp/[codename] 2.x.x amd64
  AMQP extension for PHP

php8.4-apcu/[codename] 5.x.x amd64
  APC User Cache for PHP

php8.4-bcmath/[codename] 8.4.x amd64
  Bcmath module for PHP

[additional packages...]

The codename (bookworm, bullseye, or trixie) and version numbers will match your Debian release and the current package versions in the repository.

List Loaded PHP 8.4 Modules

Alternatively, display all currently active PHP modules:

php8.4 -m

Sample output showing loaded modules:

[PHP Modules]
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
gd
hash
iconv
intl
json
libxml
mbstring
mysqli
openssl
pcre
PDO
pdo_mysql
Phar
readline
Reflection
session
SimpleXML
sockets
sodium
SPL
standard
tokenizer
xml
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

Install PHP 8.4 Development Tools

Additionally, for code coverage analysis and extension development, install these packages:

sudo apt install php8.4-pcov php8.4-dev

Specifically, the php8.4-pcov package provides lightweight code coverage reporting compatible with PHPUnit, while php8.4-dev includes headers and tools for compiling PHP extensions from source.

Run Multiple PHP Versions on Debian

How Multiple PHP Versions Work Together

The Sury repository packages each PHP version independently, so installing PHP 8.4 does not remove existing PHP installations. As a result, you can run PHP 8.2, 8.3, and 8.4 simultaneously, assigning different versions to different virtual hosts or projects.

Switch Command Line PHP Version

To manage CLI versions, use update-alternatives to configure which PHP version responds to the php command:

sudo update-alternatives --config php

You will see interactive output showing available versions:

There are 3 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
* 0            /usr/bin/php8.4   84        auto mode
  1            /usr/bin/php8.2   82        manual mode
  2            /usr/bin/php8.3   83        manual mode
  3            /usr/bin/php8.4   84        manual mode

Press <enter> to keep the current choice[*], or type selection number:

Enter the number corresponding to your preferred version. Alternatively, to set PHP 8.4 directly without the interactive prompt:

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

Switch Apache PHP Version

Similarly, when using mod_php with Apache, first disable the current PHP module and then enable the desired version:

sudo a2dismod php8.3
sudo a2enmod php8.4
sudo systemctl restart apache2

Switch Apache PHP-FPM Version

For Apache with PHP-FPM, instead swap the configuration files:

sudo a2disconf php8.3-fpm
sudo a2enconf php8.4-fpm
sudo systemctl restart apache2

Switch Nginx PHP-FPM Version

Likewise, for Nginx, update the fastcgi_pass directive in your server block to point to the desired PHP-FPM socket:

# For PHP 8.4
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;

# For PHP 8.3
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;

After making changes, test and reload Nginx:

sudo nginx -t && sudo systemctl reload nginx

Remove PHP 8.4 from Debian

Uninstall PHP 8.4 Packages

To remove PHP 8.4 and its extensions while preserving other PHP versions, run:

sudo apt remove php8.4*

Alternatively, to remove configuration files as well, use purge instead of remove:

sudo apt purge php8.4*

Finally, clean up any orphaned dependencies that were installed only for PHP 8.4:

sudo apt autoremove

Remove the Sury Repository

Furthermore, if you no longer need packages from the Sury repository, you can also remove the configuration and keyring:

sudo rm /etc/apt/sources.list.d/php.sources
sudo apt remove debsuryorg-archive-keyring
sudo apt update

Afterward, verify the repository is removed:

apt-cache policy php8.4

Expected output showing no installation candidate:

php8.4:
  Installed: (none)
  Candidate: (none)
  Version table:

Troubleshoot PHP 8.4 Installation Issues

PHP-FPM Socket Not Found

If Nginx returns a 502 Bad Gateway error, first check the Nginx error log for socket connection failures:

sudo tail -5 /var/log/nginx/error.log

A common error indicating PHP-FPM is not running looks like this:

connect() to unix:/var/run/php/php8.4-fpm.sock failed (2: No such file or directory) while connecting to upstream

Next, verify the PHP-FPM socket exists:

ls -la /var/run/php/php8.4-fpm.sock

Expected output when the socket exists:

srw-rw---- 1 www-data www-data 0 [date] [time] /var/run/php/php8.4-fpm.sock

Conversely, if the socket is missing, check PHP-FPM status and then start the service:

sudo systemctl status php8.4-fpm
sudo systemctl enable php8.4-fpm --now

Afterward, verify the socket now exists and test the configuration:

ls -la /var/run/php/php8.4-fpm.sock
sudo nginx -t && sudo systemctl reload nginx

GPG Key Import Errors

In some cases, if apt update fails with GPG signature errors after adding the Sury repository, you may see:

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]

To resolve this, reinstall the keyring package:

curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
sudo apt update

Then, verify the repository now works:

apt-cache policy php8.4

Wrong PHP Version Active

Occasionally, if php --version shows an older PHP version after installing 8.4, you need to update the alternatives system:

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

Subsequently, verify the change took effect:

php --version

Expected output confirming PHP 8.4 is now the default:

PHP 8.4.x (cli) (built: [date]) (NTS)
Copyright (c) The PHP Group
Built by Debian

Conclusion

You now have PHP 8.4 configured with property hooks, asymmetric visibility, and HTML5 DOM support on your Debian system. Moving forward, consider setting up Composer for dependency management, configuring phpMyAdmin for database administration, or securing your web server with Let’s Encrypt certificates.

Leave a Comment