Install and Upgrade to PHP 8.5 on Debian and Ubuntu

Published On20 Nov 2025

Installation and Upgrade for PHP 8.5 on Debian and Ubuntu

With support for the Pipe syntax, new URI extension, and a healthy amount of deprecations and performance improvements, PHP 8.5 is a well-polished PHP release that is now Generally-Available.

Setting up an Ubuntu or Debian server, or upgrading from a previous PHP version, is a quick process that this guide aims to explain in detail, with a list of things to watch out for.

This guide is for Debian, Ubuntu, and their derivatives, and explains how to install PHP 8.5 using pre-compiled binaries. Once installed, bug fixes and security fixes can be applied easily using apt update. The rest of the article uses the PHP APT repo maintained by Ondřej Surý. Ondrej's PHP repositories have been the de-facto repositories for PHP on Ubuntu, Debian, and their derivatives for several years. The PHP

Alternatively, it is possible to compile PHP from source.

TL;DR?

Looking for a quick guide without a lot of hand-holding? Head to quick summary section!

Backward Compatibility Breaks in PHP 8.5

While PHP 8.5 remains mostly compatible with PHP 8.4, there may be changes that break existing applications. PHP 8.5 brings several healthy deprecations, but they are to enforce the intended and recommended APIs, and do not break existing applications.

PHP 8.5 does not unbundle any PHP extensions, nor remove any PHP functions, constants, or classes that were supported in PHP 8.4 or later.

  • In PHP 8.5, the opcache extension is no longer optional. It is possible to disable opcache, but it is now always included (similar to core extensions such as PCRE, Hash, Filter, etc.). There is no need to install the Opcache extension anymore.
  • PHP 8.5 adds two new core extensions named uri and lexbor. They are also always-included.
  • PHP 8.5 introduces a new max_memory_limit INI directive to limit the memory_limit value to a highest value set by the max_memory_limit. This new directive is disabled by default.
  • The php -z CLI option is removed. It has been dysfunctional for a while, and there is a cross-version compatible alternative.
  • The disable_classes INI directive is removed.

Before continuing, please make sure to backup the system. The steps listed below are non-destructive (as in, they do not remove any files) otherwise noted. However, the importance of backups can't be stressed enough.

PHP 8.5 will receive a total of four years of security updates, of which the first two will also include bug fixes.


1. Note down existing PHP packages

When upgrading an existing PHP setup, note down the list of PHP extensions currently installed. This list can help to install the same set of PHP 8.5 extensions.

Save php -m output

php -m outputs a list of currently enabled PHP extensions. This list will come in handy to later make sure the same extensions are installed on PHP 8.5 as well:

The following command saves the php -m output to a file and display it on the screen:

php -m | tee php-m-output.txt

Save dpkg -l output

dpkg -l lists all packages installed using dpkg (which apt uses). The following command lists all of them, filters them to only packages that have php in their names, saves it to a file, and shows on the screen:

dpkg -l | grep php | tee dpkg-l-output.txt

2. Add ondrej/php PPA/DPA

As of Ubuntu 24.10, Ubuntu does not provide PHP 8.5. The PHP packages repository by Ondřej Surý contains PHP 8.5, along with several PECL PHP extensions.

Once this repo is added as a package source, the initial installations and updates can be performed using standard apt commands.


Ubuntu PPA

sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php # Press enter to confirm.
sudo apt update

Debian DPA

sudo apt-get update
sudo apt-get -y install lsb-release ca-certificates curl apt-transport-https

# Download and add the signing key
sudo curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

sudo apt-get update

3. Install New PHP 8.5 Packages

Once the repo is added to apt sources, installing the new PHP 8.5 packages is a matter of running apt install with the PHP 8.5 package name.

All PHP 8.5 packages have the php8.5- prefix, and they can be installed alongside other PHP versions.

Install PHP CLI

sudo apt install php8.5-cli

This installs the PHP 8.5 CLI executable along with the dependencies. To test if the installation went correctly, test it with php -v.

php -v

This should output the PHP version along with the optional build provider and copyright information.

php-v output
PHP 8.5 `php -v` output

Install PHP Extensions

Additional PHP extensions such as mbstring, curl, intl, readline can be installed by installing their packages that have the php8.5- prefix. For example, to install the PHP 8.5 mbstring extension, install the php8.5-mbstring package.

When upgrading from an older PHP version, refer to the dpkg-l-output.txt file saved in step 1. Make sure to install the same packages if necessary, by changing the phpX.Y-ABC pattern with php8.5-ABC.

The following command installs some of the most common PHP extensions that will cover a lot of common PHP applications:

sudo apt install php8.5-common php8.5-{bcmath,bz2,curl,gd,gmp,intl,mbstring,openssl,readline,xml,zip}

Once installed, run php -m command, which will display a list of installed PHP extensions.

Opcache extension is now always bundled, cannot be installed separately. Thus, there is no php8.5-opcache package.

Install Server APIs and Integrate

PHP setups that do not integrate with a web server (CLI-only applications, or applications that use PHP's built-in web server, for example) can skip this section.

The most common way of integrating PHP with a web server is by integrating with PHP-FPM server. There are other approaches such as the Apache mod_php module, Swoole, and FrankenPHP, that are not covered by this article.

Install PHP-FP

PHP-FPM is the recommended way to integrate PHP with web servers such as Apache (with mpm_event), Nginx, Caddy.

The php8.5-fpm package installs PHP FPM server along with systemd units to automatically start the FPM server when the server starts.

sudo apt install php8.5-fpm

To check the installation and that the php-fpm server is running, run the following:

sudo systemctl status php8.5-fpm

It should show that the FPM server is running:

php-v output
PHP 8.5 `php8.5-fpm` service status

Integrate with a web server

Apache: This configuration change is made easy by switching on the PHP 8.5 configuration file:

sudo a2enconf php8.5-fpm

Nginx: Update the fastcgi_pass directive from the old PHP FPM socket path to the new PHP 8.5 path:

- fastcgi_pass unix:/run/php/php8.4-fpm.sock;
+ fastcgi_pass unix:/run/php/php8.5-fpm.sock; 

See Nginx documentation for more information


Caddy Server: Update the reverse_proxy directive to use the new PHP 8.5 FPM server socket path:

- reverse_proxy @phpFiles unix//run/php/php8.4-fpm.sock
+ reverse_proxy @phpFiles unix//run/php/php8.5-fpm.sock

See How to use Caddy Server with PHP for more configuration details.

Additional PHP Extensions

If additional extensions are necessary, they might also be available from the repository under php8.5- prefix.

Development Tools

Debug and profiling tooling, such as Xdebug and code coverage tools, can also be installed following the same package naming convention.

Installing Xdebug or other development extensions is not recommended on production servers, unless otherwise strictly necessary.

Xdebug

Xdebug extension is not available in the repositories yet, and it will be available in the future. This notice will be removed when it is available.

sudo apt install php8.5-xdebug

Migrate Configuration

Once installed, the configuration files for the new PHP setup will be in the /etc/php/8.5 directory. The existing PHP installations are likely installed in the /etc/php/VERSION directories.

If desired, the configuration can be copied from older PHP versions. Copying over the existing files is not recommended. Instead, consider checking the differences between the two php.ini files and updating the corresponding PHP 8.5 php.ini files.

For example, the following command compares the PHP 8.5 CLI php.ini against PHP 8.5s:

diff /etc/php/8.4/cli/php.ini /etc/php/8.5/cli/php.ini

When using PHP-FPM, make sure to update the /etc/php/8.5/fpm/pool.d/www.conf file to match the older PHP-FPM runner pool configuration.

PHP modules can be installed and disabled with the phpenmod and phpdismod commands:

For example, the following command enables and disables the zip extension on PHP 8.5:

phpdismod -v 8.5 zip
phpenmod -v 8.5 zip

Remove Old PHP Versions

Once it is confirmed that the new PHP setup works correctly, the packages and services of the old PHP versions can be removed if they are no longer necessary.

sudo apt purge '^php8.4.*'

The example above shows an apt purge command that wildcard matches all PHP 8.4 packages.

Running PHP 8.5 alongside other PHP versions

If desired, PHP 8.5 installation mentioned in the steps above can co-exist with other PHP versions.

When installing PHP 8.5 CLI, it will be installed at /usr/bin/php8.5. Other PHP versions will be installed at the same location with the version name suffix (for example, PHP 8.4 at /usr/bin/php8.4). It is possible to invoke other PHP CLI versions directly by calling this path.

The default php command name will be symlinked to the latest PHP version by default. However, using the update-alternatives command, this can be changed to any other PHP version:

sudo update-alternatives --config php

This opens an interactive interface to select the alternative PHP binary path that php points to:

There are 2 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.4   84        manual mode
  2            /usr/bin/php8.5   85        manual mode

To set the path without the interactive prompt:

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

Quick Summary

1. Add PHP 8.5 sources

For Ubuntu:

sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php # Press enter to confirm.
sudo apt update

For Debian:

sudo apt-get update
sudo apt-get -y install lsb-release ca-certificates curl apt-transport-https

# Download add the signing key
sudo curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'

sudo apt-get update

2. Install new PHP 8.5 packages

sudo apt install php8.5-cli
# Adjust the extension list as necessary
sudo apt install php8.5-common php8.5-{bcmath,bz2,curl,gd,gmp,intl,mbstring,readline,xml,zip}

3. Integrate with a web server

For PHP-FPM:

sudo apt install php8.5-fpm

Then, adjust the webserver-specific PHP-FPM integration to match the PHP 8.5's listener socket address. By default, the socket will be:

/run/php/php8.5-fpm.sock

4. Remove old PHP packages

If necessary, remove the old PHP packages. For example, to remove PHP 8.4 packages:

apt purge php8.4*

Additional Information

Recent Articles on PHP.Watch

All ArticlesFeed 
How to install PHP on Windows using Winget

How to install PHP on Windows using Winget

Installing, Updating, and removing PHP on Windows 10, Windows 11, and Windows Server 2025 made with winget.
PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

A guide for Debian and Ubuntu on how to install PHP 8.4 on a new server or how to upgrade an existing PHP setup to PHP 8.4.
How to fix `mysql_native_password` not loaded errors on MySQL 8.4

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to fix the SQLSTATE[HY000] [1524] Plugin 'mysql_native_password' is not loaded errors caused in MySQL 8.4 no longer enabling the mysql_native_password plugin by default.
Subscribe to PHP.Watch newsletter for monthly updates

You will receive an email on last Wednesday of every month and on major PHP releases with new articles related to PHP, upcoming changes, new features and what's changing in the language. No marketing emails, no selling of your contacts, no click-tracking, and one-click instant unsubscribe from any email you receive.