We may earn a referral fee at no additional cost to you when you shop through the links on this page.
Upstream PHP 8.2 stops receiving security fixes on 31 December 2026, though distro-packaged PHP may be patched for longer. If you are here for PHP2Shell (CVE-2026-109618 and CVE-2026-109619), you can fix it without changing versions: see Patch PHP2Shell on Ubuntu and Debian. Otherwise, the steps below upgrade any older PHP to 8.5 for Apache (mod_php) or Nginx (PHP-FPM).
Prerequisites
- A server running Ubuntu or Debian
- Root or sudo access. The commands below are written for a user with
sudo; if you are logged in as root, omitsudo(minimal Debian installs often have nosudobinary at all) - A running web server (Apache, or Nginx with PHP-FPM)
- An existing PHP installation to upgrade from
Ubuntu 26.04: PHP 8.5 Is the Default Package
If you’re on a fresh Ubuntu 26.04 LTS (Resolute Raccoon) install, you don’t need this guide. PHP 8.5 is in the default Ubuntu archive, so apt install php pulls 8.5 with no third-party PPA. Confirm with:
apt-cache policy php
If the candidate version starts with 2:8.5, you’re set. Use our PHP and Apache install guide or PHP-FPM and Nginx install guide for the full setup. The rest of this article covers upgrading from older PHP versions on Ubuntu 22.04, 24.04, or Debian 12 and 13.
Check Your Current PHP Version
Record your current PHP version and save the list of installed extensions so you can match them after the upgrade:
php -v
PHP 8.3.32 (cli) (built: Jul 2 2026 18:10:58) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.32, Copyright (c) Zend Technologies
with Zend OPcache v8.3.32, Copyright (c), by Zend Technologies
php -m > ~/php-extensions.txt
This saved list becomes your reference point when reinstalling extensions for the new version.
Now check that version number against the support table below. If it says 8.2, you are in the cohort working to a fixed date. The number alone does not tell you whether the build has the PHP2Shell fix (the 8.3.32 build above, for one, predates it), so use the package check for that.
Which PHP Versions Are Still Supported
PHP versions are retired on a published schedule, not when your distribution decides to stop shipping them. The PHP project documents the model plainly:
Each release branch of PHP is fully supported for two years from its initial stable release. After this two year period of active support, each branch is then supported for two additional years for critical security issues only.
php.net, Supported Versions
That gives every release a four year life. Here is where the current branches stand:
| PHP version | Active support ends | Security support ends |
|---|---|---|
| 8.2 | 31 Dec 2024 | 31 Dec 2026 |
| 8.3 | 31 Dec 2025 | 31 Dec 2027 |
| 8.4 | 31 Dec 2026 | 31 Dec 2028 |
| 8.5 | 31 Dec 2027 | 31 Dec 2029 |
PHP 8.2 is already past active support, which ended on 31 December 2024, so it no longer receives general bug fixes or feature updates. It is in the security-only phase now, and that phase ends on 31 December 2026. Once a branch completes its four years, it reaches end of life and is no longer supported by the PHP project, which means no further patches even for critical issues.
Two practical notes. Your distribution runs its own clock, and it is not the same one. Debian 12 ships PHP 8.2 and is under Long Term Support until 30 June 2028, so a Debian 12 box running the packaged PHP keeps getting Debian’s security updates after the upstream date passes. If you installed PHP from the Surý repository instead, plan by the table above, although Surý sometimes backports security fixes to branches PHP no longer supports, as it did for PHP2Shell. Second, 8.5 is supported a year longer than 8.4 and three years longer than the 8.2 deadline you are leaving, so it buys the longest runway before you are back here doing this again.
The other way to stop coming back here is to let the platform own the version. On a managed host such as Cloudways the PHP version is a dropdown in the server settings, with the repository, packages and PHP-FPM restart handled behind it, and from September 2026 it can be set per application, so one site can move to a newer branch while another on the same server stays where it is. The trade is that the newest branch arrives later than upstream: Cloudways offers up to PHP 8.4 at the time of writing, while the rest of this article installs 8.5 the day the packages exist.
Patch PHP2Shell on Ubuntu and Debian
PHP2Shell is the name for two flaws in the PHP engine, CVE-2026-109618 and CVE-2026-109619, each rated 9.2 (critical) on CVSS 4.0. In its 21 October 2026 advisory, php.net says they “can allow unauthenticated remote code execution”, and it lists every way of serving PHP on the web as affected: PHP-FPM, Apache with mod_php, php-cgi, FrankenPHP and LiteSpeed, with mod_php the most exposed. The fixed releases are PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35.
You do not need a new PHP branch to fix it. Ubuntu, Debian and the Surý repositories all published patched builds of the branches they already ship on 21 October, so the job is a package update and a restart. Moving to PHP 8.5, which the rest of this guide covers, is a separate decision you can make afterwards.
How Urgent Is It?
Urgent, but not a reason to take a site offline. Sansec tested the public proof-of-concept exploits and reports that they do not work against a default PHP installation: most need the application to have a local file inclusion bug as well. Targeted attacks are real, though. Amazon reported an exploitation attempt on 17 October, four days before the fix was released.
What scanners are actually sending is a useful second opinion. Over the four and a half days from 21 October 00:00 to 25 October 12:00 UTC, which starts 14 hours before disclosure, Cloudflare’s managed rules on the 23 sites I run behind it blocked this:
Scanners are barely asking for PHP2Shell yet
Requests blocked by Cloudflare managed rules · 23 sites · 21 Oct 00:00 to 25 Oct 12:00 UTC
All four blocks matched Cloudflare’s PHP2Shell rule, which also covers CVE-2026-115560, and came from one IP address on 24 October. A short bar says mass scanning had not reached these 23 small sites by 25 October. It says nothing about targeted attacks elsewhere, and it does not mean your server is safe.
Check Whether Your PHP Is Patched
Don’t use php -v for this. Distributions fix security bugs by patching the release they ship rather than moving to the new upstream version, so a fixed Ubuntu 24.04 server still reports PHP 8.3.6, which looks thirty releases short of the 8.3.36 fix. Ask the package manager instead. Here it is on an Ubuntu 24.04 server running the distribution’s PHP that has not been updated yet, a different server from the Surý example above:
apt list --installed 'php*-common'
Listing...
php-common/noble,now 2:93ubuntu2 all [installed,automatic]
php8.3-common/noble,now 8.3.6-0maysync1 amd64 [installed,upgradable to: 8.3.6-0ubuntu0.24.04.13]
That server is still on the original 8.3.6-0maysync1 build, and apt already has the fix waiting. Compare your version with the fixed build for your release. I read these from apt on fresh installs on 25 October 2026; the Ubuntu 20.04 row comes from Canonical’s security notice, because its fix needs an Ubuntu Pro subscription:
| Release | Fixed build |
|---|---|
| Ubuntu | |
| 26.04 PHP 8.5 | 8.5.4-0ubuntu1.5resolute-security |
| 24.04 PHP 8.3 | 8.3.6-0ubuntu0.24.04.13noble-security |
| 22.04 PHP 8.1 | 8.1.2-1ubuntu2.28jammy-security |
| 20.04 PHP 7.4 | 7.4.3-4ubuntu2.29+esm5Ubuntu Pro only |
| Debian | |
| 13 PHP 8.4 | 8.4.27-1~deb13u1trixie-security |
| 12 PHP 8.2 | 8.2.35-1~deb12u1bookworm-security |
| Surý (PPA and packages.sury.org) | |
| Current PHP 8.2 to 8.5 | 8.2.35, 8.3.36, 8.4.27, 8.5.12 upstream releases |
| End of life PHP 7.4 and 8.1 | 7.4.33-31, 8.1.34-9backported fix |
For a plain yes or no, read the package changelog. Once the fix is installed it names the two CVEs, and this works for Ubuntu, Debian and Surý builds alike:
zgrep -H -m1 -E 'CVE-2026-10961[89]' /usr/share/doc/php*-common/changelog.Debian.gz
On a patched server it prints the changelog line that names them. If it prints nothing, the changelog does not mention the fix, so compare your version with the table above before deciding either way:
/usr/share/doc/php8.3-common/changelog.Debian.gz: - debian/patches/CVE-2026-109618_109619.patch: Avoid state corruption via
Install the Fix and Restart PHP
The fix arrives as an ordinary security update:
sudo apt update
sudo apt upgrade
Then run the two checks above again. The package check should now show the security pocket and no pending upgrade:
Listing...
php-common/noble,now 2:93ubuntu2 all [installed,automatic]
php8.3-common/noble-updates,noble-security,now 8.3.6-0ubuntu0.24.04.13 amd64 [installed]
Your server may have beaten you to it: the Ubuntu 24.04 and Debian 13 cloud images I checked run unattended-upgrades every day, set to install updates from the distribution’s own archive only. If your PHP is the distribution’s package, its next daily run will normally have installed the fix. If you installed PHP from the Surý repository, as the rest of this guide does, it will not have: Surý is not on that list, so nothing changes until you run the upgrade yourself.
An updated package on disk does not fix a PHP process that is already running, because that process still has the old code loaded. Do not assume the upgrade restarted everything. On Ubuntu 22.04, 24.04 and 26.04 it restarted both PHP-FPM and Apache by itself. On Debian 13 it restarted PHP-FPM and left Apache running, so mod_php, the setup php.net rates most exposed, carried on serving the old code. I saw the same result on two separate test servers. This lists any running process that still has PHP files loaded which the update replaced:
sudo grep -l 'php.*(deleted)' /proc/[0-9]*/maps 2>/dev/null | cut -d/ -f3 | xargs -r ps -o pid=,comm= -p
No output means no running process is still using files that an update replaced. It cannot tell you whether the update itself happened, so run it after the package check shows the fixed build. Any line names a process you still need to restart. This is what it printed on the Debian 13 test server straight after the upgrade:
10406 apache2
10409 apache2
10410 apache2
10411 apache2
10412 apache2
10413 apache2
Those are Apache processes, so restart Apache:
sudo systemctl restart apache2
If it names a php-fpm process instead, restart PHP-FPM, with your PHP version in place of 8.3:
sudo systemctl restart php8.3-fpm
Run the check once more afterwards. On the Debian 13 server it came back empty after the restart.
If You Cannot Patch PHP2Shell Yet
php.net is blunt about workarounds:
There are no complete mitigations, updating is the only safe choice.
php.net, PHP2Shell security advisory
Two measures narrow the risk while you schedule the update. The first is switching off session upload progress. It is on by default, and it is one confirmed route into CVE-2026-109619. The commands below use PHP 8.3; replace 8.3 with your version in every path and service name. With Apache and mod_php, add a drop-in setting and restart Apache:
echo 'session.upload_progress.enabled = 0' | sudo tee /etc/php/8.3/apache2/conf.d/99-php2shell.ini
sudo systemctl restart apache2
PHP-FPM takes its settings per pool, so the flag goes in every pool file. Open the default pool:
sudo nano /etc/php/8.3/fpm/pool.d/www.conf
Add this line at the end:
php_admin_flag[session.upload_progress.enabled] = off
Save and exit (press CTRL + X, press Y, then press ENTER)
Check that PHP-FPM has picked it up, then restart it:
sudo php-fpm8.3 -tt 2>&1 | grep upload_progress
[25-Oct-2026 12:05:44] NOTICE: php_admin_value[session.upload_progress.enabled] = 0
sudo systemctl restart php8.3-fpm
This does nothing for CVE-2026-109618, the out-of-memory bug. PHP’s interim guidance for that one is memory_limit = -1 set at the administrator level, paired with request limits in front of PHP and memory limits on the container. A value of -1 removes PHP’s per-request memory cap, so I did not apply it on my own shared server, which runs a dozen sites and has no container limit to fall back on.
The second measure is a firewall in front of PHP. Cloudflare had PHP2Shell rules running for free and paid plans from 03:02 UTC on 21 October, before the official disclosure at 14:00 UTC. They protect only traffic that passes through Cloudflare: a DNS-only record, a forgotten subdomain or a request sent straight to the server’s IP address skips them.
Keep the upload progress setting after you patch if your application changes session.serialize_handler at runtime. On 23 October PHP disclosed CVE-2026-115560, which needs that unusual setup, is not fixed by the 21 October releases, and has the same mitigation until the next routine bugfix release.
Ubuntu 20.04 and Debian 11
Older releases have no free fix in their normal archives. Ubuntu 20.04 left standard support on 31 May 2025, and its patched build ships only through Ubuntu Pro, which is free for personal and small-scale commercial use on up to five machines and a paid subscription beyond that. The Surý PPA cannot fill the gap: Launchpad listed zero published packages for 20.04 when I checked on 25 October 2026. Debian 11’s fix is available only through Freexian’s paid Extended LTS. On either release the lasting answer is a release upgrade, or a move to a newer server.
Who Patched PHP2Shell First
| When (UTC) | What happened |
|---|---|
| 17 Oct | First exploitation attempt reported, before disclosure |
| 20 Oct | Details leak ahead of the planned 22 October disclosure |
| 21 Oct, 03:02 | Cloudflare WAF rules live on free and paid plans |
| 21 Oct, 14:00 | Disclosure; PHP releases the four fixed versions |
| 21 Oct | Ubuntu, Debian and Surý publish patched builds |
| 22 Oct, 00:16 | Cloudways starts installing fixed builds on my server |
| 23 Oct | CVE-2026-115560 disclosed, fix due in the next release |
The Cloudways row is the one worth weighing. I run sites on a Cloudways server and did nothing at all: its package log shows the fixed builds going in from 00:16 UTC on 22 October, about ten hours after release, for every branch from 7.4 to 8.4, including three that the PHP project itself no longer supports. They are Surý’s Debian builds, the same packages this guide installs; what the host adds is that someone else installs them. Here is how the two approaches compared this time:
If you run one server and keep up with security updates, your own server did fine here. If you look after several sites, or PHP on a release you cannot move quickly, a managed host such as Cloudways is the better fit: on mine, PHP2Shell came down to checking a package log and the PHP version my sites report.
Add the PHP Repository
Older Ubuntu (22.04, 24.04) and Debian (12, 13) don’t ship PHP 8.5 in their default repositories. Ubuntu users add the Ondřej Surý PPA on Launchpad; Debian users add the Sury repository at packages.sury.org. These are two separate package archives with different URLs and different signing keys; use the right one for your distribution.
Ubuntu (Ondřej Surý PPA)
Configure the PPA directly with the signed-by method. This works on every Ubuntu image, including minimal cloud images where the add-apt-repository wrapper either isn’t installed or fails because the cloud network can’t reach the Launchpad API:
sudo apt install -y curl gnupg ca-certificates
sudo install -d /etc/apt/keyrings
curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14AA40EC0831756756D7F66C4F4EA0AAE5267A6C" | sudo gpg --yes --dearmor -o /etc/apt/keyrings/ondrej-php.gpg
. /etc/os-release
echo "deb [signed-by=/etc/apt/keyrings/ondrej-php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu ${VERSION_CODENAME} main" | sudo tee /etc/apt/sources.list.d/ondrej-php.list
sudo apt update
The ${VERSION_CODENAME} variable expands to your Ubuntu codename (jammy for 22.04, noble for 24.04). Once the PPA is configured, every future PHP 8.5 patch release flows in via apt upgrade. The PPA also carries older PHP versions (7.4 through 8.4) co-installable on the same host, so you can keep the previous version running while you migrate.
software-properties-common installed and unrestricted internet access), sudo add-apt-repository -y ppa:ondrej/php && sudo apt update achieves the same result in one line. The wrapper fetches the same key from the same Launchpad URL, though where it stores that key varies by release: recent Ubuntu writes a scoped signed-by source, while 22.04 typically drops the key into /etc/apt/trusted.gpg.d/ and trusts it system-wide. Both work. Use the manual setup above if you want the scoped-key layout on every release, or if you are on a minimal cloud image or locked-down environment where the wrapper is unavailable. The PPA’s signing key fingerprint is 14AA40EC0831756756D7F66C4F4EA0AAE5267A6C, fetched above from the Ubuntu keyserver. If your environment blocks keyserver.ubuntu.com, the same key is mirrored on https://launchpad.net/~ondrej/+archive/ubuntu/php.
Debian (Sury Repository)
add-apt-repository is built around Ubuntu PPAs and is not installed on Debian by default, so configure the Sury repository directly with the signed-by method. This scopes the GPG key to its own source list rather than trusting it system-wide, which is the modern replacement for the deprecated apt-key add flow:
sudo apt install -y curl gnupg ca-certificates
sudo install -d /etc/apt/keyrings
curl -fsSL https://packages.sury.org/php/apt.gpg | sudo gpg --yes --dearmor -o /etc/apt/keyrings/sury-php.gpg
. /etc/os-release
echo "deb [signed-by=/etc/apt/keyrings/sury-php.gpg] https://packages.sury.org/php/ ${VERSION_CODENAME} main" | sudo tee /etc/apt/sources.list.d/sury-php.list
sudo apt update
On Debian, ${VERSION_CODENAME} resolves to bookworm (12) or trixie (13). Debian users who prefer extrepo can run sudo apt install extrepo && sudo extrepo enable sury && sudo apt update instead. It sets up the same signed-by configuration automatically. The trailing apt update matters: enabling a repository does not refresh the package index by itself, so without it the install step below still fails with “unable to locate package”.
EXPKEYSIG or “the following signatures were invalid” on apt update, check your existing Sury source file first. If its line has signed-by=, re-run the curl ... | gpg --dearmor step above, writing the key to that exact path. If it has no signed-by, replace the line with the signed-by version above and download the key to /etc/apt/keyrings/sury-php.gpg, keeping a single Sury source file. Only after apt update runs cleanly, delete the old Sury key under /etc/apt/trusted.gpg.d/. Install PHP 8.5 and Extensions
Install the core PHP 8.5 package along with the extensions most web applications need. WordPress, Laravel, and Drupal all need at least mbstring, xml, and curl, plus the driver for your database. That is php8.5-mysql for MySQL or MariaDB; swap in php8.5-pgsql if you run PostgreSQL:
sudo apt install php8.5-cli php8.5-common php8.5-curl php8.5-mbstring php8.5-mysql php8.5-xml php8.5-zip php8.5-gd php8.5-intl php8.5-bcmath
Note what is not in that list: the bare php8.5 metapackage. It declares Depends: libapache2-mod-php8.5 | php8.5-fpm | php8.5-cgi, and apt satisfies that by installing the first alternative unless one of the others is already present. Installing php8.5 on an Nginx box therefore drags in Apache’s mod_php, and upgrading from an older PHP-FPM does not help because php8.3-fpm does not satisfy php8.5-fpm. Install the SAPI you actually want explicitly, in the next step.
php8.5-opcache package any more. apt-cache search php8.5-opcache returns no results on Ubuntu 26.04 or recent Debian. If you’re scripting an upgrade from a list of old php8.3-* packages, drop the -opcache entry to avoid an “unable to locate package” error. If your old PHP had extensions beyond the list above, this one-liner reads your installed packages for the old version and installs the 8.5 equivalents. Replace 8.3 with whatever version you’re upgrading from:
dpkg -l | awk '/^ii[[:space:]]+php8\.3-/ {print $2}' | grep -Ev '^php8\.3-(opcache|json)$' | sed 's/^php8\.3-/php8.5-/' | xargs -r sudo apt install -y
Each stage earns its place. The awk pattern keeps only lines whose status is ii, meaning actually installed, so extensions you removed earlier but never purged don’t come back, and it anchors the match to the start of the package name with the dot escaped. grep -Ev '^php8\.3-(opcache|json)$' drops two packages that have no direct 8.5 equivalent, each failing a different way. There is no php8.5-opcache at all, so apt reports “unable to locate package”. php8.5-json is worse: JSON has been built into PHP since 8.0, and the name survives only as a virtual package that seven real packages provide, so apt refuses to pick one and stops with “has no installation candidate”. Either failure aborts the whole install, which is what a PHP 7.4 server carrying php7.4-json would otherwise hit. The anchored sed rewrites only the leading php8.3- prefix rather than every occurrence of the digits. xargs -r skips the install entirely if the list comes back empty.
If you’re running Apache, also install the Apache module:
sudo apt install libapache2-mod-php8.5
If you’re running Nginx with PHP-FPM instead:
sudo apt install php8.5-fpm
Set PHP 8.5 as the default CLI version. This controls what php resolves to in your terminal, which matters for Composer, WP-CLI, and cron jobs that call /usr/bin/php:
sudo update-alternatives --set php /usr/bin/php8.5
Migrate Your php.ini Settings
PHP 8.5 installs a fresh set of configuration files at /etc/php/8.5/. Custom settings like memory_limit, upload_max_filesize, and post_max_size are not copied from your old version automatically.
To review what may need carrying over, compare the two ini files with the standard diff command. Read the result rather than copying it wholesale: the output mixes your own edits with defaults that upstream changed between the two PHP versions.
diff /etc/php/8.3/apache2/php.ini /etc/php/8.5/apache2/php.ini
Replace 8.3 with your previous version, and use fpm/ instead of apache2/ for Nginx setups. Also check /etc/php/8.5/<sapi>/conf.d/ for extension-specific ini fragments (OPcache, Redis, etc.) that may need adjusting. If you added the PHP2Shell flag to a PHP-FPM pool, the new version’s pool files under /etc/php/8.5/fpm/pool.d/ start without it. For a full guide on locating and editing these files, see finding and editing php.ini.
Configure Your Web Server
Point your web server to the new PHP version.
Apache
Disable the old PHP module and enable PHP 8.5. Only one libapache2-mod-php module can be active at a time:
sudo a2dismod php8.3
sudo a2enmod php8.5
sudo systemctl restart apache2
Substitute your actual old version number for php8.3.
Nginx with PHP-FPM
Open your Nginx site configuration and update the fastcgi_pass socket path from the old PHP version to 8.5:
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
Test the Nginx configuration, then restart PHP-FPM and reload Nginx:
sudo nginx -t
sudo systemctl restart php8.5-fpm
sudo systemctl reload nginx
Verify the Upgrade
Confirm the CLI is running PHP 8.5:
php -v
PHP 8.5.12 (cli) (built: Oct 21 2026 14:37:30) (NTS)
Copyright (c) The PHP Group
Built by Ubuntu
Zend Engine v4.5.12, Copyright (c) Zend Technologies
with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
Check that your extensions are loaded:
php -m
The CLI and web server can run different PHP versions. To verify PHP is working through your web server, create a temporary test page:
echo "<?php phpinfo();" | sudo tee /var/www/html/phpinfo.php
Open http://your-server-ip/phpinfo.php in your browser. The page should display PHP 8.5 at the top. That path assumes /var/www/html is your active document root and that the server IP serves the site you care about. If you use a different document root, or name-based vhosts where the IP lands on a different site, write the file into that site’s own root and browse its hostname instead. Delete the file immediately after checking, adjusting the path if you wrote it somewhere other than /var/www/html:
sudo rm /var/www/html/phpinfo.php
phpinfo() files after testing. They expose your full server configuration, installed modules, and environment variables to anyone who finds the URL. Remove Old PHP Versions
php8.3* can also match packages like php8.30 or php8.X3 if they exist on the system. The pattern below is the safe form: anchored to the start with ^, with the literal dot escaped (\.) and a trailing hyphen requirement so only packages starting with php8.3- (the followed-by-hyphen variants like php8.3-fpm, php8.3-cli) match, plus the bare php8.3 metapackage itself. Always inspect the proposed package list with apt-get --dry-run purge '...' before executing a destructive purge. /usr/bin/php8.3. Run crontab -l and update any references to point to /usr/bin/php8.5 or just /usr/bin/php (which uses the update-alternatives default). Once PHP 8.5 is verified and your sites are working, remove the old PHP packages. Using purge instead of remove also deletes the old configuration files:
sudo apt-get --dry-run purge '^php8\.3-' '^php8\.3$' '^libapache2-mod-php8\.3$'
Read that list before going further. --dry-run prints exactly what would be removed without touching anything, so this is the moment to catch a pattern that matches more than you intended. Once the list looks right, run the purge for real:
sudo apt purge '^php8\.3-' '^php8\.3$' '^libapache2-mod-php8\.3$'
sudo apt autoremove
Replace php8\.3 (in all three patterns) with the major.minor version you upgraded from, keeping the escaped dot and the trailing hyphen on the first pattern. The second pattern is fully anchored (^ at the start and $ at the end) so it matches only the bare php8.3 metapackage and nothing that contains php8.3 as a substring. The third pattern catches the old Apache module, which is named libapache2-mod-php8.3 rather than php8.3-something, so the first two patterns miss it. Drop that pattern if you are on Nginx.
Troubleshooting
“Unable to locate package php8.5”
The repository wasn’t added correctly, or apt update didn’t run after adding it. The check varies by distribution. On Ubuntu, confirm the PPA is active with apt-cache policy php8.5 (the candidate version should reference a Launchpad PPA). The source file lives at /etc/apt/sources.list.d/ondrej-php.list if you used the manual signed-by setup, or ondrej-ubuntu-php-*.sources / .list if you used add-apt-repository. List the directory with ls /etc/apt/sources.list.d/ | grep ondrej to find whichever applies. If both are missing, re-run the signed-by setup from the repository step above. On Debian, check that the Sury sources file exists: ls /etc/apt/sources.list.d/sury-php.list. If it’s missing, re-run the signed-by setup from the repository step above. On Debian setups using extrepo instead, the file is extrepo_sury.sources.
“GPG error: EXPKEYSIG” or “NO_PUBKEY” on apt update
The deb.sury.org signing key expired in February 2026. Servers that added the repository before then still hold the now-expired key, so apt update reports a signature error such as EXPKEYSIG or “the following signatures were invalid” on every refresh. A setup that never had the key at all reports NO_PUBKEY instead; the fix below is the same either way. Re-fetch the current key into the keyrings directory:
sudo install -d /etc/apt/keyrings
curl -fsSL https://packages.sury.org/php/apt.gpg | sudo gpg --yes --dearmor -o /etc/apt/keyrings/sury-php.gpg
sudo apt update
The command above writes the key to /etc/apt/keyrings/sury-php.gpg, so check that your Sury source line points there. If it has signed-by= with a different path, change that path to /etc/apt/keyrings/sury-php.gpg. If it has no signed-by= at all (the deprecated apt-key trust path), replace it with the signed-by example from the repository step above. Delete old Sury keys in /etc/apt/trusted.gpg.d/ only after sudo apt update runs cleanly.
Ubuntu users can hit the same NO_PUBKEY error against the PPA rather than Sury. The cause is the same missing or superseded key, but the fix uses the Launchpad keyserver instead: re-run the curl and gpg --dearmor step from the Ubuntu repository section above to refresh /etc/apt/keyrings/ondrej-php.gpg, then sudo apt update.
Apache or phpinfo() Still Shows the Old PHP Version
The Apache PHP module and the PHP CLI are two separate binaries that can point to different versions. If php -v shows 8.5 but phpinfo() does not, the web server module still points to the old version. Run sudo a2dismod php<old-version>, then sudo a2enmod php8.5, and restart Apache. For Nginx users, the equivalent issue is that the fastcgi_pass socket path still references the old PHP-FPM version.
Missing Extensions After Upgrade
PHP extensions don’t migrate automatically between versions. Use the extension matcher one-liner from the install step, or compare the output of php -m against your saved ~/php-extensions.txt to identify what’s missing.
PHP-FPM Won’t Start
Check for configuration errors with sudo php-fpm8.5 -t. The most common cause is a pool configuration file referencing a socket path from the old PHP version. Inspect the files in /etc/php/8.5/fpm/pool.d/ (see PHP-FPM config file locations for a full reference). For detailed error output, check the journal: sudo journalctl -u php8.5-fpm.
How to Revert to Your Previous PHP Version
If PHP 8.5 breaks your application and you haven’t removed the old packages yet, switch back. Run sudo apt upgrade first so the branch you return to has the PHP2Shell fix, and check it with the package check:
# Apache
sudo a2dismod php8.5
sudo a2enmod php8.3
sudo systemctl restart apache2
sudo update-alternatives --set php /usr/bin/php8.3
# Nginx with PHP-FPM
# Edit /etc/nginx/sites-available/your-site:
# fastcgi_pass unix:/run/php/php8.3-fpm.sock;
sudo systemctl restart php8.3-fpm
sudo systemctl restart nginx
sudo update-alternatives --set php /usr/bin/php8.3
Adjust the version numbers to match your setup. This is why keeping old packages installed until everything is verified pays off.
Conclusion
PHP 8.5 is now running on your server with the Ondřej Surý repository supplying future patch releases whenever you run apt upgrade; unattended-upgrades leaves them alone by default. For a complete web server setup from scratch, see our LAMP stack or LEMP stack installation guides. To fine-tune PHP settings like upload_max_filesize or memory_limit on the new version, see finding and editing php.ini.
Hi,
I have an ubuntu OS 18.04.4 LTS and php7.2, but I have followed this steps and it didn’t work for me to upgrade my php to 8.1. Anyone with a suggestion?.. Thank you.
I also have to say thank you! Quick and easy steps. Works on the first try. I only had to adapt my nginx config and it works fine. Thanks again 🙂
Thanks a bunch! I’d tried other postings without success to the point of busting the whole setup.
This one worked perfectly.
thank you
Thank you
Why do we need to execute the 4th step “Add Ondřej Surý’s PPA repository”?
Ondřej Surý is the maintainer of the PHP package in the Debian and Ubuntu operating systems. By adding his Personal Package Archive (PPA) repository to your system, you will be able to install the latest version of PHP directly from the source package maintained by Surý, rather than from the version included in the official Ubuntu repositories, which may not be the latest version.
Thank youuu so much bro !
Thank you so much!!! Very Helpful
Nice info to install
Thank you – that was very smooth! Much appeciated!!
thank you
That worked. Thanks
thanks you very much, very helpful
Thank you.. very smooth installation..
thanks a lot did work greate
Thank you for the info! Very useful!!
Just a side note:
If anyone is using memcache and redis, the extensions names are different:
For php-memcache and php-redis that used to work with php 7.x, the extensions php8.0-memcache and php8.0-redis should be used instead
Greetings
Very usefull, worked like a charm, thanks!
Thanks!!! worked on ubuntu 20.4, there were no errors.
This looks excellent, thank you. One question before I start – in my /etc directory there is are these files and directories. Will they be converted or do I need to do it manually:
/etc/apache2/mods-enabled/php7.4.load
/etc/apache2/mods-enabled/php7.4.conf
/etc/apache2/mods-available/php7.4.load
/etc/apache2/mods-available/php7.4.conf
/etc/php/7.4/cli/php.ini
/etc/php/7.4/apache2/php.ini
Hello,
I updated the php 8 on wordpress, via command line.
Everything went fine, I only had 2 plugins to disable renaming the folder, in the end everything worked out!
Greetings from Brazil.
Thank you very much for the content, it helped me!
Thanks for the comment! Obrigado!
This worked perfectly!