How to Upgrade PHP to Version 8.5 on Ubuntu (Step-by-Step Guide for 24.04 & 22.04)
By Ajay Khandal | Published:

PHP 8.5 is the latest major release of the PHP programming language, officially shipped on November 20, 2025, and it brings some of the most exciting language-level changes in years — the pipe operator (|>), a brand-new URI extension, clone-with syntax, fatal error backtraces, and better array handling with array_first() and array_last(). If you run a WordPress site, a Laravel application, a custom PHP API, or any web app on Ubuntu, upgrading to PHP 8.5 means faster execution, cleaner code, and active security support through December 31, 2027, with security-only updates until December 31, 2029.
In this complete step-by-step guide, you'll learn how to upgrade PHP to version 8.5 on Ubuntu 24.04 LTS and Ubuntu 22.04 LTS — the right way. We'll cover fresh installs, in-place upgrades from PHP 7.x, 8.0, 8.1, 8.2, 8.3, or 8.4, plus Apache, Nginx, PHP-FPM, extensions, version switching, and the most common errors people hit after upgrading.
Note: If you're still on older versions, you may want to read my earlier guides first: Upgrade PHP to 8.0 on Ubuntu and Upgrade PHP to 8.2 on Ubuntu. The same PPA-based approach applies — only the version numbers change.
Why You Should Upgrade to PHP 8.5
Before we get into the commands, here's why this upgrade is worth your time:
- Security. Older PHP versions like 8.1 and 8.2 are nearing end-of-life. Running unsupported PHP exposes your site to known vulnerabilities.
- Performance. Each release improves the Zend engine, OPcache, and JIT. PHP 8.5 also makes OPcache statically compiled — it's now always available, no longer optional.
- Modern syntax. The pipe operator, the new
Uri\Rfc3986\Uri and Uri\WhatWg\Url classes, clone() with property modification, and the #[\NoDiscard] attribute let you write cleaner, safer code.
- Better debugging. Fatal errors now ship with a full stack trace — a small change that saves hours.
- Long-term support. PHP 8.5 receives active bug fixes until late 2027 and security patches until the end of 2029.
If you're running WordPress, modern plugins and themes increasingly require PHP 8.1+. Staying on an older version blocks you from updates and breaks compatibility over time. (For a deeper look at WordPress-side modernization, see my post on WordPress dependency injection.)
What's New in PHP 8.5 — A Quick Overview
Here are the headline features you unlock the moment you upgrade:
1. The Pipe Operator (|>) Chain function calls left-to-right without nested parentheses or temporary variables.
// Before
$slug = strtolower(str_replace(' ', '-', trim($title)));
// After
$slug = $title
|> trim(...)
|> (fn($s) => str_replace(' ', '-', $s))
|> strtolower(...);
2. The New URI Extension A built-in, RFC 3986 and WHATWG-compliant URL parser — finally replacing the dated parse_url().
use Uri\Rfc3986\Uri;
$uri = new Uri('https://ajaykhandal.com/blog');
echo $uri->getHost(); // ajaykhandal.com
3. Clone With Property Modification Perfect for the "with-er" pattern in readonly classes.
$updated = clone($book, ['title' => 'New Title']);
4. #[\NoDiscard] Attribute Warns when a function's return value is ignored — great for safer APIs.
5. New Array Helpers array_first() and array_last() replace clunky reset() / end() patterns without affecting the internal pointer.
6. Fatal Error Backtraces Stack traces now appear in fatal errors — including timeout errors, which were notoriously hard to debug.
7. Other Quality-of-Life Wins Static closures and first-class callables in constant expressions, asymmetric visibility for static properties, IntlListFormatter, locale_is_right_to_left(), php --ini=diff to show only changed INI directives, the new PHP_BUILD_DATE constant, and more.
Prerequisites Before You Upgrade
Before running any commands, make sure you have:
- A server running Ubuntu 24.04 LTS (Noble Numbat) or Ubuntu 22.04 LTS (Jammy Jellyfish). Ubuntu 20.04 is also supported but reaches end of standard support in April 2025.
- Sudo access via SSH.
- A full backup of your site files and database — never upgrade production without one.
- At least one bug-fix point release in mind. As Zend recommends, waiting for 8.5.1+ before deploying to production is a sensible practice.
- A clear list of currently installed PHP extensions (we'll capture this in Step 1).
If you also need to resize disk space before the upgrade, my guide on resizing EBS volumes on AWS EC2 walks through the safest way to do it without downtime.
Step 1: Inventory Your Current PHP Setup
Before touching anything, list every PHP package currently installed. You'll use this list to install the same extensions for PHP 8.5.
# Save loaded modules
php -m | tee php-modules.txt
# Save all installed PHP packages
dpkg -l | grep php | tee php-packages.txt
Also note your current PHP version:
php -v
Keep these files — they're your safety net.
Step 2: Update Your System
Always start with a clean, updated package index:
sudo apt update && sudo apt upgrade -y
Install the helpers needed to add a PPA:
sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https -y
Step 3: Add the Ondrej PHP PPA (the Source of PHP 8.5)
Ubuntu's default repositories don't include PHP 8.5 yet. The community-standard source is the Ondrej Surý PHP PPA — maintained by the same person who maintains the official Debian PHP packages.
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
You should now see entries from ppa.launchpadcontent.net/ondrej/php/ubuntu in your sources.
If you're using Apache, Ondrej also recommends ppa:ondrej/apache2. For Nginx, use ppa:ondrej/nginx. These give you the latest matching server builds.
Step 4: Install PHP 8.5 on Ubuntu
You now have two paths depending on your web server.
Option A — PHP 8.5 with Apache
Install the Apache module and the CLI:
sudo apt install php8.5 libapache2-mod-php8.5 -y
Then disable the old PHP module and enable 8.5:
sudo a2dismod php8.3 # replace with your old version
sudo a2enmod php8.5
sudo systemctl restart apache2
Option B — PHP 8.5 with Nginx (PHP-FPM)
Nginx doesn't run PHP directly — it talks to PHP-FPM over a Unix socket. Install FPM and the CLI:
sudo apt install php8.5-fpm php8.5-cli -y
sudo systemctl enable --now php8.5-fpm
Then update your Nginx server block to point to the new socket:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
}
Reload Nginx:
sudo nginx -t && sudo systemctl reload nginx
Step 5: Install Common PHP 8.5 Extensions
Most real-world apps — WordPress, Laravel, Symfony, Drupal — need a standard extension set. Install it in one shot:
sudo apt install -y \
php8.5-common \
php8.5-mysql \
php8.5-xml \
php8.5-curl \
php8.5-mbstring \
php8.5-zip \
php8.5-gd \
php8.5-intl \
php8.5-bcmath \
php8.5-imagick \
php8.5-soap \
php8.5-readline \
php8.5-opcache
Need a quick reference for which extension matters?
| Extension |
Why You Need It |
mysql |
Database connectivity (WordPress, Laravel) |
mbstring |
Multibyte string handling (UTF-8) |
xml |
RSS feeds, SOAP, sitemaps |
curl |
API calls, remote requests |
gd / imagick |
Image processing (uploads, thumbnails) |
zip |
Plugin installs, backups |
intl |
Internationalization, locale formatting |
bcmath |
High-precision math (e-commerce, finance) |
opcache |
Bytecode caching for performance |
For a fully scripted server provisioning workflow that handles this automatically, see my guide on setting up a CI/CD pipeline for WordPress development.
Step 6: Verify the PHP 8.5 Installation
Check the CLI version:
php -v
Expected output:
PHP 8.5.x (cli) (built: Nov 20 2025)
Copyright (c) The PHP Group
Zend Engine v4.5.0, Copyright (c) Zend Technologies
with Zend OPcache v8.5.x, Copyright (c), by Zend Technologies
To verify the web server is also serving PHP 8.5, create a temporary info file:
sudo nano /var/www/html/info.php
Paste:
<?php phpinfo();
Visit http://your-domain.com/info.php in a browser. You should see "PHP Version 8.5.x" at the top.
Important: Delete info.php immediately after testing — it leaks server details.
sudo rm /var/www/html/info.php
Step 7: Switch the Default PHP CLI Version
If you have multiple PHP versions installed (very common during an upgrade), the php command may still point to the old one. Fix it with update-alternatives:
sudo update-alternatives --config php
You'll see something like:
There are 4 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/php8.3 83 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
Type the selection number for /usr/bin/php8.5 and press Enter.
Repeat for phar and phpize if needed:
sudo update-alternatives --config phar
sudo update-alternatives --config phpize
Step 8: Migrate Your php.ini Settings
Your old php.ini had hand-tuned values for memory_limit, upload_max_filesize, post_max_size, max_execution_time, etc. PHP 8.5 ships with defaults — you need to bring your changes over.
Compare and migrate:
sudo diff /etc/php/8.3/fpm/php.ini /etc/php/8.5/fpm/php.ini
sudo diff /etc/php/8.3/cli/php.ini /etc/php/8.5/cli/php.ini
Don't blindly copy the old file over — new directives in 8.5 (like max_memory_limit) and removed/changed options can break things. Edit /etc/php/8.5/fpm/php.ini and update individual values. Common ones for WordPress:
memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 120
Restart FPM after changes:
sudo systemctl restart php8.5-fpm
Step 9: Test Your Application
This is where you don't skip steps. Test:
- The homepage and a few internal pages
- Admin login (WordPress, Laravel, etc.)
- File uploads and image processing
- Form submissions and checkout flows
- Cron jobs and CLI scripts (
wp-cron.php, artisan schedule:run, etc.)
- Plugins or packages that interact with deprecated functions
Watch your error logs:
sudo tail -f /var/log/php8.5-fpm.log
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/apache2/error.log
If you're running advanced WordPress queries with custom fields and meta lookups, double-check them — see my deep-dive on advanced WP_Query techniques for performance considerations after a PHP upgrade.
Step 10: Clean Up Old PHP Versions (Optional)
Once PHP 8.5 is humming, remove old versions to free disk space and reduce attack surface:
sudo apt purge 'php8.3*' -y
sudo apt autoremove -y
Replace 8.3 with whichever version you're done with. Don't run this until you've fully validated 8.5 in production.
PHP 8.5 Deprecations You Should Watch For
Every minor release deprecates some features. Here are the notable ones in 8.5 — review your code now to avoid surprises in PHP 9.0:
- Non-canonical scalar type casts like
(boolean), (double), (integer), (binary) — use (bool), (float), (int), (string).
mysqli_execute() is deprecated in favor of mysqli_stmt_execute().
curl_close() and curl_share_close() — already no-ops since PHP 8.0.
xml_parser_free() — also a no-op since PHP 8.0.
- Backticks for shell execution (in some contexts).
Run your codebase through static analysis tools like PHPStan, Psalm, or Rector to catch these automatically before deploying.
Common Errors After Upgrading PHP to 8.5 (and How to Fix Them)
1. "502 Bad Gateway" on Nginx Nginx is still pointing to the old FPM socket. Update fastcgi_pass to unix:/run/php/php8.5-fpm.sock and reload Nginx.
2. WordPress shows a white screen Usually a deprecated function in a plugin/theme. Enable WP_DEBUG in wp-config.php, check wp-content/debug.log, and update the offender.
3. php: command not found or wrong version Run sudo update-alternatives --config php and select PHP 8.5.
4. Could not open input file: artisan You're running the wrong CLI binary. Use php8.5 artisan ... explicitly or set 8.5 as default.
5. Apache still serving old PHP You forgot to disable the old module. Run sudo a2dismod php8.3 && sudo a2enmod php8.5 && sudo systemctl restart apache2.
6. Missing extension errors (Class "Imagick" not found, etc.) Install the missing extension: sudo apt install php8.5-imagick && sudo systemctl restart php8.5-fpm.
Quick Reference: All Commands in One Place
# 1. Inventory
php -m | tee php-modules.txt
dpkg -l | grep php | tee php-packages.txt
# 2. Update + add PPA
sudo apt update && sudo apt upgrade -y
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
# 3a. Apache
sudo apt install php8.5 libapache2-mod-php8.5 -y
sudo a2dismod php8.3 && sudo a2enmod php8.5
sudo systemctl restart apache2
# 3b. Nginx
sudo apt install php8.5-fpm php8.5-cli -y
sudo systemctl enable --now php8.5-fpm
# 4. Common extensions
sudo apt install php8.5-{common,mysql,xml,curl,mbstring,zip,gd,intl,bcmath,opcache} -y
# 5. Verify
php -v
# 6. Switch default CLI
sudo update-alternatives --config php
# 7. (Later) Cleanup
sudo apt purge 'php8.3*' -y && sudo apt autoremove -y
Need Help With Your PHP / WordPress Upgrade?
Upgrading PHP looks simple in a tutorial, but production environments have plugins, custom code, cron jobs, and integrations that don't always cooperate. If you're a business owner who can't afford downtime — or a developer who would rather hand this off — I help clients upgrade PHP, audit deprecations, refactor legacy code, and migrate sites without losing SEO or breaking functionality.
Take a look at my custom WordPress development services or my WordPress migration services if you'd like a professional to handle the upgrade end-to-end. You can also browse all my services or more posts on the blog.
Frequently Asked Questions
Q1. When was PHP 8.5 released?
Ans: PHP 8.5 was officially released on November 20, 2025. It's the latest stable major release of PHP.
Q2. Is PHP 8.5 available in Ubuntu's default repositories?
Ans: No. Ubuntu 24.04 ships with PHP 8.3 by default, and PHP 8.5 isn't in the standard repos. Use the Ondrej Surý PPA (ppa:ondrej/php) — the community-standard source.
Q3. Will upgrading to PHP 8.5 break my WordPress site?
Ans: Most modern, well-maintained WordPress plugins and themes are compatible. Older or abandoned plugins may use deprecated functions. Always test on a staging site first and check wp-content/debug.log for warnings.
Q4. Can I run multiple PHP versions side by side on Ubuntu?
Ans: Yes. The Ondrej PPA is co-installable — you can have PHP 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5 installed simultaneously and switch between them with update-alternatives or per-site in PHP-FPM.
Q5. How long will PHP 8.5 be supported?
Ans: PHP 8.5 receives active bug fixes through December 31, 2027 and security-only updates through December 31, 2029.
Q6. Should I upgrade straight from PHP 7.4 to 8.5?
Ans: You can, but it's risky. PHP 7.4 → 8.5 means crossing the major 7.x → 8.x boundary, which introduced many breaking changes. I recommend upgrading in stages (e.g., 7.4 → 8.1 → 8.5) and testing at each step. My PHP 8.0 upgrade guide and PHP 8.2 upgrade guide are good intermediate stops.
Q7. Do I need to upgrade Apache or Nginx too?
Ans: Not necessarily. PHP 8.5 works fine with the Apache and Nginx versions in Ubuntu 22.04 / 24.04. But if you want the latest server builds, add ppa:ondrej/apache2 or ppa:ondrej/nginx.
Q8. Is OPcache still optional in PHP 8.5?
Ans: No — and this is a meaningful change. OPcache is now always statically compiled into PHP, just like ext/date, ext/hash, and ext/standard. You no longer need to install it separately.
Wrapping Up
Upgrading PHP to version 8.5 on Ubuntu is straightforward when you follow the right sequence: inventory → add PPA → install PHP 8.5 + extensions → switch web server → verify → migrate php.ini → test → clean up. The Ondrej PPA does the heavy lifting, and PHP 8.5 itself rewards you with a cleaner syntax (pipe operator, clone-with), modern URL parsing, far better debugging via stack traces in fatal errors, and long-term security support through 2029.
If this guide saved you time, consider sharing it with your team — and if you run into a tricky edge case, drop me a line through my contact page or check out more posts on the blog for related WordPress, server, and DevOps tutorials.
Happy coding on PHP 8.5! 🚀