How to Install PHP 8.5 on Ubuntu 26.04, 24.04 and 22.04

Install PHP 8.5 on Ubuntu 26.04, 24.04 and 22.04 with the pipe operator, URI extension, and clone-with syntax. Includes Apache, Nginx, and PHP-FPM setup.

Last updatedAuthorJoshua JamesRead time8 minGuide typeUbuntu

Install PHP 8.5 on Ubuntu when your application needs the newer URI extension, pipe operator, clone() property updates, or array helper functions covered in the official PHP 8.5 release announcement. Ubuntu 26.04 already includes PHP 8.5 packages in its archive, while Ubuntu 24.04 and 22.04 need an external source for the php8.5 package family.

Ondrej Sury’s APT repository at packages.sury.org currently publishes suites for Ubuntu 26.04, 24.04, and 22.04. The Sury source gives all three supported LTS releases the same package naming pattern and currently provides newer PHP 8.5 point releases than the Ubuntu 26.04 archive. PHP 8.5 remains in active support through December 31, 2027, and security support through December 31, 2029, according to PHP’s supported versions table.

Install PHP 8.5 on Ubuntu

The Sury repository is a third-party APT source. Use it when you want the current PHP 8.5 branch across Ubuntu 26.04, 24.04, and 22.04, or when you need co-installable PHP branches for staged application upgrades. If you prefer Ubuntu’s default branch and do not need PHP 8.5 specifically, install the default PHP on Ubuntu instead.

Refresh APT and Confirm the Ubuntu Codename

Start with a fresh package index, then confirm which Ubuntu codename and architecture the host reports. The repository source uses the codename in the Suites: field, and this workflow is validated from Sury’s package indexes for Ubuntu 26.04 on amd64 and arm64, plus Ubuntu 24.04 and 22.04 on amd64, arm64, and armhf.

sudo apt update

These package-management commands need sudo privileges. If your account is not allowed to use sudo yet, add the account with Add a New User to Sudoers on Ubuntu before continuing.

grep '^VERSION_CODENAME=' /etc/os-release
dpkg --print-architecture
VERSION_CODENAME=resolute
amd64

Ubuntu 26.04 uses resolute, Ubuntu 24.04 uses noble, and Ubuntu 22.04 uses jammy. Ubuntu supports additional architectures such as ppc64el, s390x, and riscv64, but the Sury PHP indexes for these suites currently publish only amd64, arm64, and armhf. The guarded source block below uses the combinations where the article’s core PHP 8.5 workflow is available.

Add the Sury PHP Repository on Ubuntu

Install the small prerequisite set, then save the Sury signing key as a binary keyring. The curl command in Linux guide explains the -fsSLo flags if you want to adapt this download pattern for another repository later.

sudo apt install -y ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg

Load Ubuntu’s release metadata in the current shell and check the host against the validated Sury suite and architecture combinations.

. /etc/os-release
ARCH="$(dpkg --print-architecture)"
printf 'Using suite: %s\nUsing architecture: %s\n' "$VERSION_CODENAME" "$ARCH"
Using suite: resolute
Using architecture: amd64

Create a DEB822 source file for the Sury PHP repository. The guarded block stops before writing the source file when the host does not match a validated Ubuntu release and Sury package-index combination.

. /etc/os-release
ARCH="$(dpkg --print-architecture)"

case "$VERSION_CODENAME:$ARCH" in
  resolute:amd64|resolute:arm64|noble:amd64|noble:arm64|noble:armhf|jammy:amd64|jammy:arm64|jammy:armhf)
  printf '%s\n' \
    'Types: deb' \
    'URIs: https://packages.sury.org/php/' \
    "Suites: $VERSION_CODENAME" \
    'Components: main' \
    "Architectures: $ARCH" \
    'Signed-By: /usr/share/keyrings/deb.sury.org-php.gpg' | sudo tee /etc/apt/sources.list.d/php.sources > /dev/null
    ;;
  *)
    printf 'This workflow covers Ubuntu 26.04 on amd64/arm64 and Ubuntu 24.04/22.04 on amd64/arm64/armhf; this host reports %s/%s.\n' "$VERSION_CODENAME" "$ARCH" >&2
    false
    ;;
esac

Refresh APT again after the source file is written.

sudo apt update

Then confirm that php8.5 is available from Sury.

apt-cache policy php8.5
php8.5:
  Installed: (none)
  Candidate: 8.5.6-2+0~20260511.17+ubuntu26.04~1.gbp39d451
  Version table:
     8.5.6-2+0~20260511.17+ubuntu26.04~1.gbp39d451 500
        500 https://packages.sury.org/php resolute/main amd64 Packages
     8.5.4-0ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu resolute/main amd64 Packages

On Ubuntu 26.04, apt-cache policy can show both Sury and Ubuntu archive candidates for PHP 8.5. The selected candidate should be the newer Sury build when that repository has the higher version. On Ubuntu 24.04 and 22.04, the Sury entry is normally the only php8.5 candidate.

Compare PHP 8.5 Web Server Setups on Ubuntu

Choose the integration that matches the web server already running on the host. If the server layer is not installed yet, start with Install Apache on Ubuntu or Install Nginx on Ubuntu first.

SetupPackagesBest ForTrade-off
Apache with mod_phpapache2, libapache2-mod-php8.5Short-lived labs and simple local developmentApache runs PHP inside its worker model
Apache with PHP-FPMapache2, php8.5-fpmProduction Apache sites that need separate PHP worker poolsRequires Apache proxy and FPM configuration
Nginx with PHP-FPMnginx, php8.5-fpm, php8.5-cliLEMP stacks and high-traffic PHP sitesNginx needs a FastCGI block that points at the PHP 8.5 socket

PHP-FPM is the better default for production because it keeps PHP in a separate service with its own pool settings, logs, and restart path. Use mod_php only when you need the shortest Apache-only setup for a local or disposable host.

If your target is a container image such as php:8.5-apache or php:8.5-fpm, treat that as a Docker workflow rather than an Ubuntu APT package name. Set up Docker on Ubuntu first, then use the official PHP image tag in your container or Compose configuration.

Install PHP 8.5 with Apache mod_php on Ubuntu

The mod_php path loads PHP as an Apache module. It is convenient for quick development stacks but is less flexible than PHP-FPM.

sudo apt install -y apache2 libapache2-mod-php8.5
sudo systemctl restart apache2

Confirm that Apache loaded the PHP module.

sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep php
 php_module (shared)

Install PHP 8.5 with Apache and PHP-FPM on Ubuntu

This setup keeps Apache in front while PHP runs through the dedicated php8.5-fpm service.

sudo apt install -y apache2 php8.5-fpm
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php8.5-fpm
sudo systemctl enable php8.5-fpm --now
sudo systemctl restart apache2

If you previously tested libapache2-mod-php8.5 on the same host, disable mod_php with sudo a2dismod php8.5 before enabling the FPM configuration.

Check the FPM service, socket, and Apache configuration state.

systemctl is-active php8.5-fpm
test -S /run/php/php8.5-fpm.sock && echo 'php8.5-fpm socket exists'
sudo /usr/sbin/apache2ctl -M 2>/dev/null | grep proxy_fcgi
test -L /etc/apache2/conf-enabled/php8.5-fpm.conf && echo 'php8.5-fpm configuration enabled'
active
php8.5-fpm socket exists
 proxy_fcgi_module (shared)
php8.5-fpm configuration enabled

Install PHP 8.5 with Nginx and PHP-FPM on Ubuntu

Nginx always hands PHP requests to FastCGI, so install the FPM service and CLI package together.

sudo apt install -y nginx php8.5-fpm php8.5-cli
sudo systemctl enable php8.5-fpm --now

Add this location block to the relevant Nginx server block so PHP requests reach the PHP 8.5 socket.

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

Check the service state, confirm that the socket exists, then test the Nginx configuration before reloading the service.

systemctl is-active php8.5-fpm
test -S /run/php/php8.5-fpm.sock && echo 'php8.5-fpm socket exists'
sudo nginx -t
active
php8.5-fpm socket exists
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo systemctl reload nginx

Verify the PHP 8.5 CLI on Ubuntu

Confirm the installed interpreter version before moving on to extensions or application setup.

php --version
PHP 8.5.6 (cli) (built: May 11 2026 18:05:42) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.5.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.6, Copyright (c), by Zend Technologies

Install PHP 8.5 Extensions on Ubuntu

Most PHP applications need extra modules beyond the base interpreter. The package set here covers common requirements for WordPress, Laravel, API clients, database access, image handling through GD, XML processing, SOAP clients, and multibyte text.

Install Common PHP 8.5 Extensions on Ubuntu

Install the modules your application needs. The grouped package list uses PHP 8.5 packages verified across the allowed Sury suite and architecture combinations above. APCu is handled separately because its PHP 8.5 package is not published for every ARM combination.

sudo apt install -y php8.5-curl php8.5-mysql php8.5-gd php8.5-zip php8.5-intl php8.5-bcmath php8.5-readline php8.5-mbstring php8.5-xml php8.5-soap

Check APCu before installing it. If apt-cache policy shows a candidate for your release and architecture, install the package normally.

apt-cache policy php8.5-apcu
if apt-cache policy php8.5-apcu | grep -q 'Candidate: (none)'; then
  printf 'php8.5-apcu is not available for this Ubuntu release and architecture.\n'
else
  sudo apt install -y php8.5-apcu
fi

There is no separate php8.5-opcache, php8.5-json, or php8.5-tokenizer package in the Sury PHP 8.5 source. Zend OPcache and JSON ship with the base PHP packages, while php8.5-common provides Tokenizer compatibility.

Restart the PHP handler after installing extensions so web requests load the new modules.

sudo systemctl restart php8.5-fpm

If the host uses Apache with mod_php instead of PHP-FPM, restart Apache with sudo systemctl restart apache2 instead.

Verify a few commonly needed modules and confirm that OPcache is active in the CLI build.

php8.5 -m | grep -E '^(curl|gd|mbstring|mysqli|xml)$'
php --version | grep 'Zend OPcache'
curl
gd
mbstring
mysqli
xml
    with Zend OPcache v8.5.6, Copyright (c), by Zend Technologies

Search Available PHP 8.5 Extensions on Ubuntu

Search the active package sources before adding optional modules such as Redis, Memcached, Imagick, Xdebug, or PCOV. Availability differs by Ubuntu release, architecture, and source.

apt-cache pkgnames php8.5- | sort | head -n 6

On the amd64 validation path, relevant output includes package names like these.

php8.5-amqp
php8.5-apcu
php8.5-ast
php8.5-bcmath
php8.5-bz2
php8.5-cgi

Install PHP 8.5 Development Headers on Ubuntu

Install php8.5-dev only on development hosts that compile PHP extensions or need tools such as phpize. It pulls compiler and packaging dependencies that are usually unnecessary on production web servers.

sudo apt install -y php8.5-dev

Verify the development helper reports the PHP 8.5 API branch.

phpize8.5 --version
Configuring for:
PHP Version:             8.5
PHP Api Version:         20250925
Zend Module Api No:      20250925
Zend Extension Api No:   420250925

Configure PHP 8.5 on Ubuntu

PHP keeps separate configuration trees for the CLI and FPM SAPIs. CLI changes affect terminal scripts, while FPM changes affect web applications served through Apache with FPM or Nginx.

Locate PHP 8.5 Configuration Files on Ubuntu

Check the CLI configuration path first.

php8.5 --ini | head -3
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 web workloads that use PHP-FPM, edit /etc/php/8.5/fpm/php.ini and restart php8.5-fpm after changes.

Adjust PHP 8.5 FPM Settings on Ubuntu

Open the FPM configuration file for web-facing settings such as upload limits, memory limits, and execution timeouts.

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

Common production values look like this, but tune them for the application and available memory.

upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
max_execution_time = 120
max_input_vars = 3000
display_errors = Off
expose_php = Off

Restart PHP-FPM and verify the saved values directly from the FPM configuration file.

sudo systemctl restart php8.5-fpm
grep -E '^(upload_max_filesize|post_max_size|memory_limit|max_execution_time|max_input_vars|display_errors|expose_php)' /etc/php/8.5/fpm/php.ini
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 256M
max_execution_time = 120
max_input_vars = 3000
display_errors = Off
expose_php = Off

For a deeper FPM pool walkthrough, use Configure PHP-FPM on Ubuntu after the PHP 8.5 packages are installed.

Run Multiple PHP Versions on Ubuntu

Sury packages PHP branches independently, so PHP 8.5 can coexist with PHP 8.4, PHP 8.3, or the release default branch. Keep CLI, Apache, and Nginx switching separate because each layer chooses its PHP version differently.

Switch the PHP CLI Version on Ubuntu

Use update-alternatives to select which installed PHP binary responds to the unversioned php command.

sudo update-alternatives --config php

The menu only lists PHP branches installed on that host. Choose the entry that points to /usr/bin/php8.5 when PHP 8.5 should be the default CLI interpreter.

Set PHP 8.5 directly when you do not need the interactive menu.

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

Switch Apache to PHP 8.5 on Ubuntu

For Apache with mod_php, disable any older PHP module that is currently enabled, then enable PHP 8.5.

for module in php8.1 php8.3 php8.4; do
  if sudo a2query -m "$module" >/dev/null 2>&1; then
    sudo a2dismod "$module"
  fi
done
sudo a2enmod php8.5
sudo systemctl reload apache2

Switch Apache PHP-FPM to PHP 8.5 on Ubuntu

For Apache with PHP-FPM, switch the enabled FPM configuration instead of the mod_php module.

for conf in php8.1-fpm php8.3-fpm php8.4-fpm; do
  if sudo a2query -c "$conf" >/dev/null 2>&1; then
    sudo a2disconf "$conf"
  fi
done
sudo a2enconf php8.5-fpm
sudo systemctl reload apache2

Switch Nginx PHP-FPM to PHP 8.5 on Ubuntu

For Nginx, update the fastcgi_pass socket in the relevant server block and reload Nginx after the syntax check passes.

fastcgi_pass unix:/run/php/php8.5-fpm.sock;
sudo nginx -t
sudo systemctl reload nginx

Update or Remove PHP 8.5 on Ubuntu

APT owns both the Sury repository packages and Ubuntu’s own PHP packages, so routine updates and removals should stay inside APT.

Update PHP 8.5 on Ubuntu

Refresh package metadata, then upgrade the installed PHP 8.5 package family without forcing unrelated packages into the same transaction.

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

Restart PHP-FPM when the host uses FPM for web requests.

sudo systemctl restart php8.5-fpm
php8.5 --version

Remove PHP 8.5 Packages from Ubuntu

Remove the PHP 8.5 branch packages while preserving other PHP versions and the repository source.

sudo apt remove 'php8.5*'

Use purge only when you also want to remove package-managed configuration under /etc/php/8.5/. Back up edited php.ini files or pool files first.

sudo apt purge 'php8.5*'

Review orphaned dependencies before deleting them. Reused systems may already have unrelated autoremovable packages.

sudo apt autoremove --dry-run

Continue only when the preview lists packages you intend to remove.

sudo apt autoremove

Remove the Sury PHP Repository from Ubuntu

Remove the Sury source and signing key only when no remaining PHP branch on the host depends on that repository for updates.

sudo rm -f /etc/apt/sources.list.d/php.sources /usr/share/keyrings/deb.sury.org-php.gpg
sudo apt update
apt-cache policy php8.5

After removing Sury on Ubuntu 26.04, apt-cache policy php8.5 may still show Ubuntu’s own PHP 8.5 candidate. On Ubuntu 24.04 and 22.04, the candidate normally disappears because those releases do not ship php8.5 in their default archives.

Troubleshoot PHP 8.5 on Ubuntu

Fix Duplicate PHP Repository Sources on Ubuntu

If APT still contacts an older Launchpad PHP source, remove that source before using the Sury packages.sury.org entry. Duplicate PHP sources can make candidates confusing or trigger Signed-By conflicts.

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

If add-apt-repository is unavailable or the old file was edited manually, use Remove a PPA from Ubuntu to identify and remove the leftover source safely.

Fix Unable to Locate php8.5-opcache or php8.5-tokenizer on Ubuntu

APT reports no candidate for php8.5-opcache or php8.5-tokenizer because those are not separate installable Sury packages for PHP 8.5.

E: Unable to locate package php8.5-opcache
E: Couldn't find any package by glob 'php8.5-opcache'

Install the base CLI package and common files instead.

sudo apt install -y php8.5-cli php8.5-common

Then check the bundled modules.

php8.5 -m | grep '^tokenizer$'
php --version | grep 'Zend OPcache'
tokenizer
    with Zend OPcache v8.5.6, Copyright (c), by Zend Technologies

Fix the PHP-FPM Socket Not Found Error on Ubuntu

If Nginx returns a 502 Bad Gateway error, check the Nginx error log for a missing PHP-FPM socket. The tail command in Linux is useful for reading the newest log lines without opening the full file.

sudo tail -5 /var/log/nginx/error.log
connect() to unix:/run/php/php8.5-fpm.sock failed (2: No such file or directory) while connecting to upstream

Confirm the service is active and the socket exists.

systemctl is-active php8.5-fpm
test -S /run/php/php8.5-fpm.sock && echo 'php8.5-fpm socket exists'
active
php8.5-fpm socket exists

Start PHP-FPM if the service is inactive, then test and reload Nginx.

sudo systemctl enable php8.5-fpm --now
sudo nginx -t
sudo systemctl reload nginx

Fix the Wrong PHP Version on Ubuntu

If php --version still reports an older branch, set the CLI alternative to PHP 8.5.

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

Verify the active binary after changing the alternative.

command -v php
php --version
/usr/bin/php
PHP 8.5.6 (cli) (built: May 11 2026 18:05:42) (NTS)

Conclusion

PHP 8.5 is now installed on Ubuntu through the Sury APT repository, with Apache or Nginx connected through the handler that matches your stack. For common next steps, add Composer on Ubuntu, deploy WordPress with Nginx and MariaDB on Ubuntu, or tune Nginx FastCGI Cache on Ubuntu.

Share this guide

Help another Linux user troubleshoot faster

Share this guide with someone troubleshooting Linux systems or saving it for later.

Follow LinuxCapable

Want more LinuxCapable guides in Google?

Add LinuxCapable as a preferred source so Google can show our tutorials more often in Top Stories and mark them as preferred in AI Mode and AI Overviews when relevant.

Add LinuxCapable as a preferred source on Google
Search LinuxCapable

Need another guide?

Search LinuxCapable for package installs, commands, troubleshooting, and follow-up guides related to what you just read.

Found this guide useful?

Support LinuxCapable to keep tutorials free and up to date.

Buy me a coffeeBuy me a coffee
Before commenting, please review our Comments Policy.
Formatting tips for your comment

You can use basic HTML to format your comment. Useful tags currently allowed in published comments:

You type Result
<code>command</code> command
<strong>bold</strong> bold
<em>italic</em> italic
<a href="https://example.com">link</a> link
<blockquote>quote</blockquote> quote block

Add to the discussion

Questions, fixes, command output, and version notes help keep this guide current.

Verify before posting: