PHP 8.5 introduces the pipe operator (|>) for cleaner function chaining, a built-in URI extension for standards-compliant URL handling, the clone() function with property updates, and array_first()/array_last() helper functions. These features streamline common coding patterns while improving code readability. On all Debian versions, PHP 8.5 is available through Ondřej Surý’s PHP repository, which provides the latest PHP releases for Debian systems.
In this guide, you will learn how to import the Sury repository, install PHP 8.5 with Apache on Debian or Nginx on Debian, configure PHP-FPM for production workloads, and run multiple PHP versions side by side. By the end, you will have PHP 8.5 configured and ready to power WordPress with Apache on Debian or WordPress with Nginx on Debian, Laravel, or any application that benefits from the pipe operator 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 | Mature JIT optimization with broad extension compatibility | WordPress 6.x, Laravel 11, Drupal 10 sites needing stable features with security support through December 2028 | Requires Sury repository on Debian 11/12; available in Debian 13 default repositories |
| PHP 8.3 | Typed class constants, json_validate(), #[\Override] attribute | Stable JIT with proven production reliability | Production systems requiring proven stability with security support through December 2027 | Requires Sury repository on all Debian versions; predecessor to 8.4 |
Recommendation: Choose PHP 8.5 when your application benefits from the pipe operator for cleaner function composition, the URI extension for standards-compliant URL parsing, or the new array helper functions. PHP 8.5 will receive active support through late 2027 and security fixes until late 2029. However, if your application already runs well on PHP 8.4, that version remains fully supported through December 2028. For systems where you prefer official Debian security team maintenance over newer features, the distro default PHP remains a solid choice.
Explore PHP 8.5 Feature Highlights
PHP 8.5 provides tangible benefits for specific development scenarios. First, the pipe operator (|>) enables left-to-right function chaining, replacing deeply nested calls with readable sequential transformations. Additionally, the built-in URI extension provides secure URL parsing according to RFC 3986 and WHATWG standards, eliminating inconsistencies from manual URL handling.
Furthermore, the clone() function now accepts property arrays, simplifying the “with-er” pattern for readonly classes. Similarly, array_first() and array_last() retrieve array elements more cleanly than $arr[array_key_first($arr)] patterns. The #[\NoDiscard] attribute helps catch unused return values, and fatal errors now include backtraces for easier debugging. For a complete list of changes, see the official PHP 8.5 release announcement.
Add the PHP 8.5 Repository on Debian
Note: PHP 8.5 is not yet available in any Debian default repositories, including Debian 13 (Trixie). All Debian versions require the Sury repository to install PHP 8.5.
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.
Debian 11 users: The
lsb-releasepackage is critical because minimal Debian 11 installations do not include thelsb_releasecommand by default. The repository configuration step below uses$(lsb_release -cs)to detect your release codename automatically.
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
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 to include the new source:
sudo apt update
Finally, confirm PHP 8.5 is available from the Sury repository:
apt-cache policy php8.5
Expected output showing the Sury repository as the package source:
php8.5:
Installed: (none)
Candidate: 8.5.0-1+0~20xxxxxx.xx+[codename]~1.gbpxxxxx
Version table:
8.5.0-1+0~20xxxxxx.xx+[codename]~1.gbpxxxxx 500
500 https://packages.sury.org/php [codename]/main amd64 Packages
Version numbers and build strings change with each release. Replace
[codename]with your Debian release:trixiefor Debian 13,bookwormfor Debian 12, orbullseyefor Debian 11. Your output will show the current version available from the Sury repository.
Install PHP 8.5 on Debian
At this point, select the installation method that matches your web server configuration. Apache on Debian users can choose between mod_php (simpler setup) or PHP-FPM (better resource management). In contrast, Nginx on Debian requires PHP-FPM exclusively.
Compare Installation Methods
| Method | Best For | Multi-Version | Process Isolation |
|---|---|---|---|
| Apache mod_php | Development, low-traffic sites | No (one version per Apache instance) | None (runs inside Apache) |
| Apache + PHP-FPM | Production, shared hosting | Yes (pools per version) | Separate process pools |
| Nginx + PHP-FPM | High-traffic production | Yes (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.5 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.5 libapache2-mod-php8.5
Afterward, restart Apache to activate the PHP module:
sudo systemctl restart apache2
Then, verify PHP is loaded:
php --version
Expected output:
PHP 8.5.0 (cli) (built: Nov 20 2025 19:25:46) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.5.0, Copyright (c) Zend Technologies
with Zend OPcache v8.5.0, Copyright (c), by Zend Technologies
Option 2: Install PHP 8.5 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.5-fpm libapache2-mod-fcgid
If mod_php is installed from a previous configuration, disable it before enabling PHP-FPM. Run
sudo a2dismod php8.5if you installed PHP 8.5 mod_php above, or replacephp8.5with your currently active version (e.g.,php8.4,php8.2) if migrating from an older PHP installation.
Once installed, enable the required Apache modules and PHP-FPM configuration:
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.5-fpm
Enable and start PHP-FPM, then restart Apache to apply changes:
sudo systemctl enable php8.5-fpm --now
sudo systemctl restart apache2
Finally, confirm PHP-FPM is running:
sudo systemctl status php8.5-fpm
Expected output confirming active status:
● php8.5-fpm.service - The PHP 8.5 FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php8.5-fpm.service; enabled; preset: enabled)
Active: active (running) since [date and time]
Main PID: [pid] (php-fpm8.5)
Tasks: [number]
Memory: [size]
CPU: [time]
CGroup: /system.slice/php8.5-fpm.service
Option 3: Install PHP 8.5 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.5 php8.5-fpm php8.5-cli
Next, enable and start PHP-FPM:
sudo systemctl enable php8.5-fpm --now
Then, verify PHP-FPM status:
sudo systemctl status php8.5-fpm
Expected output confirming active status:
● php8.5-fpm.service - The PHP 8.5 FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php8.5-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.5:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.5-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.5 Installation
Regardless of which method you chose, confirm PHP 8.5 installed correctly:
php --version
The output should display PHP 8.5.x with Zend OPcache enabled, similar to the verification output shown in the Apache mod_php section above.
Install PHP 8.5 Extensions on Debian
Install Common PHP 8.5 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.5-{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.5-jsonpackage exists. Thephp8.5-xmlpackage provides DOM, SimpleXML, XMLReader, and XMLWriter support. Thephp8.5-xdebugextension significantly impacts performance—install it only on development systems, not production servers.
After installation, restart your PHP handler to load the new extensions. For PHP-FPM users:
sudo systemctl restart php8.5-fpm
If you installed PHP 8.5 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.5 -m | grep -E 'curl|mysqli|gd|mbstring|xml'
Expected output showing the extensions are active:
curl gd mbstring mysqli xml
PHP 8.5 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 for financial calculations and cryptography.
- 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 DOM and SimpleXML support.
- php-xdebug: Step debugging and profiling for development environments.
- php-soap: SOAP web services client and server functionality.
Search Available PHP 8.5 Extensions
To explore additional options, list all available PHP 8.5 modules from the repository:
apt search php8.5-
Sample output showing available extensions:
Sorting... Full Text Search... php8.5-amqp/[codename] 2.x.x amd64 AMQP extension for PHP php8.5-apcu/[codename] 5.x.x amd64 APC User Cache for PHP php8.5-bcmath/[codename] 8.5.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.5 Modules
Alternatively, display all currently active PHP modules:
php8.5 -m
Sample output showing loaded modules:
[PHP Modules] calendar Core ctype curl date dom exif fileinfo filter gd hash iconv intl json lexbor libxml mbstring mysqli openssl pcre PDO pdo_mysql Phar readline Reflection session SimpleXML sockets sodium SPL standard tokenizer uri xml Zend OPcache zip zlib [Zend Modules] Zend OPcache
Install PHP 8.5 Development Tools
Additionally, for code coverage analysis and extension development, install these packages:
sudo apt install php8.5-pcov php8.5-dev
Specifically, the php8.5-pcov package provides lightweight code coverage reporting compatible with PHPUnit, while php8.5-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.5 does not remove existing PHP installations. As a result, you can run PHP 8.2, 8.3, 8.4, and 8.5 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 4 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.5 85 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 4 /usr/bin/php8.5 85 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.5 directly without the interactive prompt:
sudo update-alternatives --set php /usr/bin/php8.5
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.4
sudo a2enmod php8.5
sudo systemctl restart apache2
Switch Apache PHP-FPM Version
For Apache with PHP-FPM, instead swap the configuration files:
sudo a2disconf php8.4-fpm
sudo a2enconf php8.5-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.5
fastcgi_pass unix:/var/run/php/php8.5-fpm.sock;
# For PHP 8.4
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
After making changes, test and reload Nginx:
sudo nginx -t && sudo systemctl reload nginx
Remove PHP 8.5 from Debian
Uninstall PHP 8.5 Packages
To remove PHP 8.5 and its extensions while preserving other PHP versions, run:
sudo apt remove php8.5*
APT will display the packages to be removed before proceeding:
The following packages will be removed: libapache2-mod-php8.5 php8.5 php8.5-cli php8.5-common php8.5-curl php8.5-fpm php8.5-gd php8.5-mbstring php8.5-mysql php8.5-opcache php8.5-xml php8.5-zip [additional packages...]
Alternatively, to remove configuration files as well, use purge instead of remove:
sudo apt purge php8.5*
Finally, clean up orphaned dependencies that were installed automatically with PHP 8.5, such as Apache modules, FPM dependencies, and shared libraries:
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
The apt update command refreshes the package cache so the removed repository no longer appears. Afterward, verify the repository is removed:
apt-cache policy php8.5
Expected output showing no installation candidate:
php8.5: Installed: (none) Candidate: (none) Version table:
Troubleshoot PHP 8.5 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.5-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.5-fpm.sock
Expected output when the socket exists:
srw-rw---- 1 www-data www-data 0 [date] [time] /var/run/php/php8.5-fpm.sock
Conversely, if the socket is missing, check PHP-FPM status and then start the service:
sudo systemctl status php8.5-fpm
sudo systemctl enable php8.5-fpm --now
Afterward, verify the socket now exists and test the configuration:
ls -la /var/run/php/php8.5-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.5
Wrong PHP Version Active
Occasionally, if php --version shows an older PHP version after installing 8.5, you need to update the alternatives system:
sudo update-alternatives --set php /usr/bin/php8.5
Subsequently, verify the change took effect:
php --version
Expected output confirming PHP 8.5 is now the default:
PHP 8.5.0 (cli) (built: Nov 20 2025 19:25:46) (NTS) Copyright (c) The PHP Group Built by Debian
Conclusion
You now have PHP 8.5 configured with the pipe operator, URI extension, and new array helper functions on your Debian system. Moving forward, consider setting up Composer on Debian for dependency management, configuring phpMyAdmin with Nginx on Debian for database administration, containerizing your application with Docker on Debian, or securing your web server with Let’s Encrypt certificates for Nginx on Debian or Apache on Debian.