How to Install PHP 8.5 on Ubuntu

PHP 8.5 introduces the built-in URI extension for secure URL parsing, the pipe operator (|>) for cleaner function chaining, and the clone() syntax for modifying properties during cloning. These additions reduce boilerplate code and improve readability in data processing workflows. On Ubuntu, PHP 8.5 is available through Ondrej Sury’s PHP PPA, which provides co-installable PHP versions with regular security updates.

The steps below walk through adding the Sury PPA, installing PHP 8.5 with Apache or Nginx, configuring PHP-FPM for production workloads, and managing extensions. After completing these steps, you will have PHP 8.5 configured and ready to power WordPress, Laravel, or any application that benefits from the pipe operator and improved URI handling.

Select a PHP Version for Your Ubuntu System

Compare PHP Versions Available for Ubuntu

Ubuntu repositories and the Sury PPA 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 FocusSupport StatusBest ForTrade-offs
PHP (Distro Default)Stability with Ubuntu security team maintenanceMatches Ubuntu release lifecycleProduction servers prioritizing official Ubuntu updates and minimal external dependenciesVersion varies by release (8.1 on 22.04, 8.3 on 24.04)
PHP 8.5URI extension, pipe operator, clone with propertiesActive support through December 2026; security through December 2028Modern applications using functional programming patterns, URL parsing, and immutable object patternsRequires Sury PPA; community-maintained updates
PHP 8.3Typed class constants, json_validate(), readonly property cloningActive support through December 2025; security through December 2027WordPress 6.x, Laravel 11, Drupal 10 sites needing stable features with long security supportDefault on 24.04; requires Sury PPA on 22.04
PHP 8.2Readonly classes, DNF types, null/false standalone typesActive support through December 2024; security through December 2026Legacy applications requiring PHP 8.2 compatibility, WordPress 6.1+ minimum requirementsOlder feature set; security-only phase beginning

Recommendation: Choose PHP 8.5 for new projects that benefit from the pipe operator for cleaner data transformations, the URI extension for secure URL handling, or the clone-with pattern for immutable objects. If your application already runs well on the distro default PHP and you prefer official Ubuntu security team maintenance, that version remains a solid choice.

This guide covers Ubuntu 22.04 LTS and 24.04 LTS installations. The Ondrej Sury PPA provides PHP 8.5 packages for both releases, and commands work identically on supported versions unless otherwise noted.

Explore PHP 8.5 Feature Highlights

PHP 8.5 provides tangible benefits for specific development scenarios. First, the new URI extension offers object-oriented APIs to parse and modify URIs according to RFC 3986 and WHATWG URL standards, replacing error-prone string manipulation with type-safe methods. Additionally, the pipe operator (|>) enables chaining callables left-to-right, passing values through multiple functions without intermediary variables.

Furthermore, the clone() syntax now accepts an associative array to modify properties during cloning, simplifying the “with-er” pattern for readonly classes. The #[\NoDiscard] attribute warns when return values are ignored, helping prevent mistakes in APIs where the returned value is important. Additionally, array_first() and array_last() functions provide cleaner access to array endpoints. For a complete list of changes, see the official PHP 8.5 release announcement.

Add the PHP 8.5 PPA on Ubuntu

Update System Packages

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

sudo apt update
sudo apt upgrade

Install Prerequisites for PPA Management

Next, the software-properties-common package provides the add-apt-repository command needed to add PPAs. Install it along with other common utilities:

sudo apt install software-properties-common ca-certificates lsb-release -y

The apt-transport-https package is no longer needed on Ubuntu 22.04 and newer. HTTPS support is now built into APT directly, so you can skip any guides that still list it as a prerequisite.

Add the Ondrej Sury PHP PPA

The Ondrej Sury PPA provides co-installable PHP versions from 5.6 through 8.5, allowing you to run multiple PHP versions side by side. Add the repository with:

sudo add-apt-repository ppa:ondrej/php -y

After adding the PPA, refresh the package index to make the new packages available:

sudo apt update

Then, confirm PHP 8.5 is available from the PPA:

apt-cache policy php8.5

Expected output showing the Sury PPA as the package source:

php8.5:
  Installed: (none)
  Candidate: 8.5.1-1+ubuntu24.04.1+deb.sury.org+1
  Version table:
     8.5.1-1+ubuntu24.04.1+deb.sury.org+1 500
        500 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main amd64 Packages

The version numbers and codename will match your Ubuntu release. On Ubuntu 22.04, the output shows jammy instead of noble. Your output will display the current version available from the Sury PPA.

Install PHP 8.5 on Ubuntu

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

MethodWeb ServerProcess ModelBest For
Apache mod_phpApache onlyEmbedded in workerDevelopment environments; simplest setup
Apache + PHP-FPMApacheSeparate pool managersProduction sites; better memory management
Nginx + PHP-FPMNginxSeparate pool managersHigh-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. Therefore, use mod_php only for development or low-traffic sites where simplicity matters more than resource efficiency.

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

You should see expected output similar to:

PHP 8.5.x (cli) (built: [date]) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.x, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.x, 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: sudo a2dismod php8.5

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

sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.5-fpm

Now, 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

You should see expected output similar to:

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

Install PHP 8.5 Extensions on Ubuntu

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,readline,memcached,redis,mbstring,apcu,xml,soap}

JSON support is built into PHP 8.0 and later, so no separate php8.5-json package exists. The php8.5-xml package provides DOM, SimpleXML, XMLReader, and XMLWriter support. The php8.5-mysql package includes both MySQLi and MySQLnd drivers.

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
libxml
mbstring
mysqli
xml
xmlreader
xmlwriter

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: MariaDB and MySQL database connectivity via MySQLi and MySQLnd.
  • 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.
  • php-imagick: Advanced image processing through ImageMagick.
  • php-memcached and php-redis: Distributed caching backends for session storage and object caching.
  • 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, SimpleXML, and XSL support.
  • php-soap: SOAP web services client and server functionality.

Search Available PHP 8.5 Extensions

To explore additional options, you can 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/noble 2.x.x amd64
  AMQP extension for PHP

php8.5-apcu/noble 5.x.x amd64
  APC User Cache for PHP

php8.5-bcmath/noble 8.5.x amd64
  Bcmath module for PHP

[additional packages...]

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
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-xdebug php8.5-pcov php8.5-dev

The php8.5-xdebug extension significantly impacts performance. Install it only on development systems, not production servers. For production-safe code coverage, use php8.5-pcov instead.

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.

Configure PHP 8.5 Settings

Locate PHP Configuration Files

PHP 8.5 maintains separate configuration files for CLI (command line) and PHP-FPM (web server). Consequently, to find the active configuration file for each environment, run:

php8.5 --ini | head -3

Expected output showing CLI configuration paths:

Configuration File (php.ini) Path: /etc/php/8.5/cli
Loaded Configuration File:         /etc/php/8.5/cli/php.ini
Scan for additional .ini files in: /etc/php/8.5/cli/conf.d

For PHP-FPM (used by Apache with PHP-FPM or Nginx), the configuration file is at /etc/php/8.5/fpm/php.ini instead. Notably, changes to CLI settings do not affect web applications, and vice versa.

Adjust Common PHP Settings

To modify settings for web applications using PHP-FPM, edit the FPM configuration file:

sudo nano /etc/php/8.5/fpm/php.ini

Common settings to adjust based on your application requirements:

; Maximum upload file size (default: 2M)
upload_max_filesize = 64M

; Maximum POST data size (must be >= upload_max_filesize)
post_max_size = 64M

; Maximum memory per script (default: 128M)
memory_limit = 256M

; Maximum script execution time in seconds (default: 30)
max_execution_time = 120

; Maximum input variables (default: 1000)
max_input_vars = 3000

For production servers, also consider setting display_errors = Off to prevent exposing sensitive information, expose_php = Off to hide the PHP version in HTTP headers, and enabling OPcache with appropriate settings for your workload.

After making changes, restart PHP-FPM to apply them:

sudo systemctl restart php8.5-fpm

Then verify the CLI reflects the new settings:

php8.5 -i | grep upload_max_filesize

Expected output confirming the new value:

upload_max_filesize => 64M => 64M

The php8.5 -i command shows CLI settings from /etc/php/8.5/cli/php.ini. To verify web application settings, create a phpinfo() test page or check /etc/php/8.5/fpm/php.ini directly. Changes to one configuration file do not affect the other.

Run Multiple PHP Versions on Ubuntu

How Multiple PHP Versions Work Together

The Sury PPA packages each PHP version independently, so installing PHP 8.5 does not remove existing PHP installations. As a result, you can run PHP 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 then 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.5   85        auto mode
  1            /usr/bin/php8.3   83        manual mode
  2            /usr/bin/php8.4   84        manual mode
  3            /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.4
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;

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

After making changes, test and reload Nginx:

sudo nginx -t && sudo systemctl reload nginx

Remove PHP 8.5 from Ubuntu

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 then 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:

Warning: The purge command permanently deletes PHP configuration files in /etc/php/8.5/. If you have customized php.ini or pool configurations, back them up first.

sudo apt purge php8.5*

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

sudo apt autoremove

Remove the Ondrej Sury PPA

If you no longer need packages from the Sury PPA, remove the configuration:

sudo add-apt-repository --remove ppa:ondrej/php -y
sudo apt update

After removing the PPA, verify PHP 8.5 is no longer available:

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

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.x (cli) (built: [date]) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.x, Copyright (c) Zend Technologies

Extension Not Loading After Installation

If an extension appears installed but is not loading, first confirm it is installed:

dpkg -l | grep php8.5-curl

Expected output showing the package is installed:

ii  php8.5-curl  8.5.x-1+ubuntu24.04.1+deb.sury.org+1  amd64  CURL module for PHP

Then check if the extension is enabled in the PHP configuration:

php8.5 -m | grep curl

If the extension is installed but not appearing, restart the PHP handler:

# For PHP-FPM
sudo systemctl restart php8.5-fpm

# For Apache mod_php
sudo systemctl restart apache2

Update PHP 8.5 on Ubuntu

PHP 8.5 receives updates through the Sury PPA. Consequently, to update to the latest point release while keeping other system packages unchanged, run:

sudo apt update
sudo apt install --only-upgrade php8.5*

This command updates all PHP 8.5 packages (CLI, FPM, extensions) without upgrading unrelated system packages. After updating, restart PHP-FPM to apply changes:

sudo systemctl restart php8.5-fpm

Then, verify the new version:

php8.5 --version

Conclusion

You now have PHP 8.5 configured with the URI extension, pipe operator, and clone-with syntax on your Ubuntu system. Moving forward, consider setting up phpMyAdmin for database administration, configuring Nginx FastCGI caching for better performance, or deploying WordPress with Nginx and MariaDB.

Useful Links

For additional resources and documentation:

  • PHP Official Website: Visit the official PHP website for information about the programming language, its features, and download options.
  • PHP 8.5 Release Notes: Explore the release notes for PHP 8.5 to learn about new features, improvements, and changes.
  • PHP 8.5 ChangeLog: Review the changelog for PHP 8 to see the detailed list of changes and updates in each release.
  • PHP Documentation: Access comprehensive documentation for detailed guides on using and programming with PHP.
  • PHP Supported Versions: Check current PHP version support status and end-of-life dates.

Leave a Comment