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.
The steps below walk through importing the Sury repository where needed, installing PHP 8.4 with Apache or Nginx, configuring PHP-FPM for production workloads, and running multiple PHP versions side by side. After completing these steps, 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.5, 8.4, 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 Version | Primary Focus | Performance | Best For | Trade-offs |
|---|---|---|---|---|
| PHP (Distro Default) | Stability with Debian security team maintenance | Varies by version; Debian 12’s PHP 8.2 includes JIT compilation and OPcache | Production servers prioritizing official Debian updates and minimal external dependencies | Version varies by release (8.4 on Debian 13, 8.2 on Debian 12, 7.4 on Debian 11) |
| PHP 8.5 | Pipe operator, URI extension, clone with properties, array helpers | Improved JIT and continued IR-based JIT framework refinements | Projects leveraging function chaining, advanced URL handling, or needing array_first()/array_last() | Newest release; requires Sury repository on all Debian versions |
| PHP 8.4 | Property hooks, asymmetric visibility, HTML5 DOM API | Continued JIT improvements; new IR-based JIT framework | Projects using modern OOP patterns, applications requiring array_find() and BCMath object API | Requires Sury repository on Debian 11/12; available in Debian 13 default repositories |
| PHP 8.3 | Typed class constants, json_validate(), readonly property cloning | Mature JIT optimization with broad extension compatibility | WordPress 6.x, Laravel 11, Drupal 10 sites needing stable features with security support through December 2027 | Requires 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. If you need the pipe operator or array_first()/array_last() helpers, consider PHP 8.5 instead. 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. For a complete list of changes, see the official PHP 8.4 release announcement.
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
Before adding external repositories, synchronize your package index and upgrade installed packages to ensure compatibility:
sudo apt update
sudo apt upgrade
Compare Repository Configuration Methods
Two methods are available for adding the Sury PHP repository. The comparison below helps you choose the approach that best fits your workflow:
| Method | GPG Key Management | Debian Support | Steps Required | Best For |
|---|---|---|---|---|
| extrepo (Recommended) | Automatic | 11, 12, 13 | 3 commands | Most users; quick setup with minimal configuration |
| Manual Repository | Manual download | 11, 12, 13 | 5 commands | Scripted deployments, custom configurations, or learning APT internals |
For most users, the extrepo method is recommended because it handles GPG key management automatically and configures the correct repository URL for your Debian version with a single command.
Option 1: Add Repository with extrepo (Recommended)
The extrepo tool is Debian’s official method for managing external repositories. It handles GPG keys automatically and configures the correct repository URL for your Debian version. First, install extrepo:
sudo apt install extrepo -y
Next, enable the Sury PHP repository:
sudo extrepo enable sury
After enabling the repository, refresh the package index:
sudo apt update
Then, confirm PHP 8.4 is available:
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.gbpxxxxxx
Version table:
8.4.x-1+0~20xxxxxx.xx+debian12~1.gbpxxxxxx 500
500 https://packages.sury.org/php bookworm/main amd64 Packages
The version numbers and codename will match your Debian release. Replace
bookwormwithbullseyefor Debian 11. Your output will show the current version available from the Sury repository.
With the repository configured via extrepo, proceed to the installation section below.
Option 2: Add Repository Manually
If you prefer manual repository configuration or need explicit control over the setup, follow these steps instead. First, install the prerequisite packages:
sudo apt install ca-certificates curl lsb-release -y
These packages handle SSL certificate validation, HTTP downloads, and distribution release detection.
Minimal installation users: The
lsb-releasepackage may be missing on minimal Debian installations, cloud images, or Docker containers. The repository configuration below uses$(lsb_release -cs)to detect your release codename automatically. Alternatively, you can replace$(lsb_release -cs)with your codename directly:trixiefor Debian 13,bookwormfor Debian 12, orbullseyefor Debian 11.
Next, 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 the 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
All current Debian versions fully support the DEB822
.sourcesformat. Debian 13 uses it by default, while Debian 12 and 11 still commonly use legacy.listfiles on older installations.
After adding the repository, refresh the package index:
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.gbpxxxxxx
Version table:
8.4.x-1+0~20xxxxxx.xx+debian12~1.gbpxxxxxx 500
500 https://packages.sury.org/php bookworm/main amd64 Packages
The version numbers and codename will match your Debian release. Replace
bookwormwithbullseyefor Debian 11. Your output will show the current version available from the Sury repository.
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 PHP Installation Methods
| Method | Web Server | Process Model | Best For |
|---|---|---|---|
| Apache mod_php | Apache only | Embedded in worker | Development environments; simplest setup |
| Apache + PHP-FPM | Apache | Separate pool managers | Production sites; better memory management |
| Nginx + PHP-FPM | Nginx | Separate pool managers | High-traffic production; static file performance |
For production environments, PHP-FPM is recommended because it runs as a separate process pool, allowing finer control over memory usage, timeouts, and process lifecycle. Use mod_php only for development or low-traffic sites where simplicity matters more than resource efficiency.
Install PHP 8.4 from Debian 13 Default Repositories
Debian 13 (Trixie) includes PHP 8.4 in the default repositories, so no external repository is needed. First, verify the package is available:
apt-cache policy php8.4
Expected output from the default Debian 13 repositories:
php8.4:
Installed: (none)
Candidate: 8.4.x-1
Version table:
8.4.x-1 500
500 http://deb.debian.org/debian trixie/main amd64 Packages
Then, install PHP 8.4 with your preferred web server integration and proceed to the extension installation section:
# For Apache with mod_php
sudo apt install php8.4 libapache2-mod-php8.4
# For Apache with PHP-FPM
sudo apt install php8.4-fpm libapache2-mod-fcgid
# For Nginx with PHP-FPM
sudo apt install php8.4 php8.4-fpm php8.4-cli
Debian 11 and 12 users: You must complete the Sury repository setup in the previous section before using the installation methods below. Debian 13 users can skip to the extension installation section after running the command above.
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
The output should display PHP 8.4.x with Zend OPcache enabled, similar to the verification output shown in the Apache mod_php section above.
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-jsonpackage exists. Thephp8.4-xmlpackage provides DOM, SimpleXML, XMLReader, and XMLWriter support. Thephp8.4-xdebugextension significantly impacts performance, so install it only on development systems and not production servers.
After installation, restart your PHP handler to load the new extensions. For PHP-FPM users:
sudo systemctl restart php8.4-fpm
If you installed PHP 8.4 with Apache mod_php instead of PHP-FPM, restart Apache to load the new extensions:
sudo systemctl restart apache2
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 libxml mbstring mysqli xml xmlreader xmlwriter
PHP 8.4 Extension 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\HTMLDocumentclass 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, ortrixie) 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*
APT will display the packages to be removed before proceeding:
The following packages will be removed: libapache2-mod-php8.4 php8.4 php8.4-cli php8.4-common php8.4-curl php8.4-fpm php8.4-gd php8.4-mbstring php8.4-mysql php8.4-opcache php8.4-xml php8.4-zip [additional packages...]
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
If you no longer need packages from the Sury repository, remove the configuration based on how you originally added it:
Debian 13 users: If you installed PHP 8.4 from the default Debian repositories without adding the Sury repository, skip this repository removal section.
If you used extrepo:
sudo extrepo disable sury
sudo apt update
If you configured the repository manually:
sudo rm /etc/apt/sources.list.d/php.sources
sudo apt remove debsuryorg-archive-keyring
sudo apt update
After removing the repository, verify PHP 8.4 is no longer available from Sury:
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
lsb_release Command Not Found
On minimal Debian installations, cloud images, or Docker containers, you may encounter this error when running the repository configuration command:
bash: lsb_release: command not found
This occurs because the lsb-release package is not installed. You have two options to resolve this:
Option 1: Install lsb-release
sudo apt install lsb-release -y
Option 2: Replace $(lsb_release -cs) with your codename directly
Use trixie for Debian 13, bookworm for Debian 12, or bullseye for Debian 11. For example, on Debian 12:
cat <<EOF | sudo tee /etc/apt/sources.list.d/php.sources
Types: deb
URIs: https://packages.sury.org/php/
Suites: bookworm
Components: main
Signed-By: /usr/share/keyrings/debsuryorg-archive-keyring.gpg
EOF
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
Update PHP 8.4 on Debian
PHP 8.4 receives updates through the repository you configured during installation. To update to the latest point release while keeping other system packages unchanged, run:
sudo apt update
sudo apt install --only-upgrade php8.4*
This command updates all PHP 8.4 packages (CLI, FPM, extensions) without upgrading unrelated system packages. After updating, restart PHP-FPM to apply changes:
sudo systemctl restart php8.4-fpm
Then, verify the new version:
php8.4 --version
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, containerizing your application with Docker, or securing your web server with Let’s Encrypt certificates for Nginx or Apache.