PHP 8.1 reached upstream end of life on 31 December 2025, and its last release from the PHP project was 8.1.34. It is still the default PHP on Ubuntu 22.04, though, and the Ubuntu security team keeps patching it there, so an app that cannot leave 8.1 yet has a supported home on 22.04. On Ubuntu 24.04 you get PHP 8.1 from the Ondřej Surý PPA, which still builds it for noble with backported fixes.
This guide keeps a legacy app alive. You pick the right package source, install the FPM build without Apache, prove the build carries the PHP2Shell fix, and run 8.1 next to a supported PHP so you can move sites one at a time. For a new project, use the PHP 8.2 on Ubuntu guide or a newer branch. Every command below was run on Ubuntu 22.04 and 24.04 servers in November 2026.
Pick the PHP 8.1 source for your release
Where your PHP 8.1 comes from decides who patches it and for how long, so settle this before you install anything. The PHP project no longer ships 8.1 releases at all. What you get is a distro or PPA build with security fixes backported, and the version string on each one looks very different.
| Ubuntu release | PHP 8.1 source | Build we installed | Who patches it |
|---|---|---|---|
| 22.04 (jammy) | Ubuntu archive, no extra repo | 8.1.2-1ubuntu2.28 | Ubuntu security team to May 2027, then Ubuntu Pro to 2032 (esm-infra for cli and common, esm-apps for fpm, intl and zip) |
| 24.04 (noble) | ppa:ondrej/php | 8.1.34-9+ubuntu24.04.1+deb.sury.org+1 | Ondřej Surý, no fixed end date |
| 20.04 and 18.04 | none patched | not tested | nobody for 8.1, so upgrade the OS |
Ubuntu 22.04 is the safer home because the patching is Canonical’s job and has a published end date. The PPA is one person’s work, and the notice it printed when we added it says the repository is being merged into packages.sury.org, with the PPA still usable for jammy and noble. That’s fine for a migration window, but don’t plan years around it.
If you’re still on Ubuntu 20.04 or 18.04, there is no free patched PHP 8.1 for you. Launchpad lists the Ondřej PPA as publishing for jammy and noble only, and the stock PHP on those releases is 7.4 and 7.2, whose fixes now come through Ubuntu Pro. Upgrade the OS to 22.04 first, then follow the 22.04 path below.
Install PHP 8.1
Below you install PHP 8.1 Ubuntu packages on 22.04 first, then the PPA build on 24.04. On both releases you want php8.1-fpm and php8.1-cli rather than the php8.1 metapackage, because the metapackage pulls in Apache with mod_php and starts it on port 80. With FPM you choose the web server yourself, and you can run more than one PHP version behind it.
On Ubuntu 22.04
Refresh the package index, then ask apt which PHP 8.1 builds it can see. A server that isn’t reading the security pocket would install the original 2022 build without any warning, so this check matters.
sudo apt update
apt-cache policy php8.1-fpm php8.1-cli
The candidate you see must come from jammy-security or jammy-updates. Look at the components too, because php8.1-cli sits in main while php8.1-fpm sits in universe, and that difference decides which Ubuntu Pro service patches each one once standard support ends.

If your list stops at the plain jammy line, fix /etc/apt/sources.list before going further. Otherwise, install the FPM and CLI packages.
sudo apt install -y php8.1-fpm php8.1-cli
Nine packages land, about 22 MB on disk, and none of them is Apache.
The following NEW packages will be installed:
bzip2 mailcap mime-support php-common php8.1-cli php8.1-common php8.1-fpm
php8.1-opcache php8.1-readline
0 upgraded, 9 newly installed, 0 to remove and 2 not upgraded.
Need to get 5264 kB of archives.
After this operation, 21.7 MB of additional disk space will be used.
Confirm the CLI version and that the FPM service came up. The package enables and starts php8.1-fpm on its own, so you don’t need a separate systemctl enable.
php -v
systemctl status php8.1-fpm --no-pager
The upstream number stays at 8.1.2 for the whole life of Ubuntu 22.04. The part after the dash is the Ubuntu package revision, and that is what moves with each security update, so read the whole string rather than the first three digits.

The pool listens on /run/php/php8.1-fpm.sock, which is the path you point your web server at later.
On Ubuntu 24.04 with the Ondřej PPA
Ubuntu 24.04 ships PHP 8.3 and nothing older, so on a stock server apt-cache policy php8.1-cli prints nothing at all. Add the PPA, which brings its own signing key and refreshes the index in one step.
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
Read the repository notice it prints once, because it tells you where this PPA is heading.
Description:
This repository is in process of being merged into https://packages.sury.org/php/;
For Ubuntu Resolute, https://packages.sury.org/php/ is the canonical way of getting PHP packages, for previous releases, I will provide a simple way how to migrate to the new repositories in upcoming weeks, you can still use this repository for Ubuntu Jammy and Ubuntu Noble.
Check that apt now offers PHP 8.1 from the PPA, then install the same two packages you’d use on 22.04.
apt-cache policy php8.1-fpm
sudo apt install -y php8.1-fpm php8.1-cli
php -v
The PPA build reports the last upstream point release, 8.1.34, with the backports carried in its -9 package revision. Six packages were installed here, since 24.04 already had the rest.

One side effect catches people later. With the PPA added, apt also prefers the PPA build of PHP 8.3 (8.3.36 in our run) over the stock 8.3.6 build, so your next apt upgrade moves any stock 8.3 sites on that server to the PPA builds too. Plan for that if other sites share the box.
Check the build for the PHP2Shell fix
PHP2Shell is the pair of remote code execution bugs CVE-2026-109618 and CVE-2026-109619 that PHP fixed on 21 October 2026 in 8.5.12, 8.4.27, 8.3.36 and 8.2.35. The PHP security advisory says plainly that 8.1 gets no release, only minimal source backports for people who build PHP themselves. So on 8.1, your package source is the only thing standing between you and those bugs, and you should prove the patch landed.
The package changelog names the CVEs a build fixes, and the same command works for both sources.
zgrep -E 'CVE-2026-10961[89]' /usr/share/doc/php8.1-common/changelog.Debian.gz
Any match means the build is patched, and no output means it predates the fix. Minimized images such as the Docker ubuntu image drop most of /usr/share/doc, so a version comparison is the fallback, and the threshold depends on where the package came from:
- Ubuntu archive build on 22.04:
8.1.2-1ubuntu2.28or later - Ondřej PPA build on 24.04:
8.1.34-9or later
Don’t mix them up. If you use the 22.04 threshold on a PPA build you get a false patched, because 8.1.34 always sorts above 8.1.2 whatever the revision. Run the line that matches your source.
# Ubuntu 22.04, Ubuntu archive build
dpkg --compare-versions "$(dpkg-query -W -f='${Version}' php8.1-common)" ge 8.1.2-1ubuntu2.28 && echo patched || echo VULNERABLE
# Ubuntu 24.04, ppa:ondrej/php build
dpkg --compare-versions "$(dpkg-query -W -f='${Version}' php8.1-common)" ge 8.1.34-9 && echo patched || echo VULNERABLE
Both lab servers passed. The 22.04 changelog lists each CVE on its own line under the patch name, and the version check agrees.

The PPA build on 24.04 carries both CVEs on a single changelog line instead, followed by the patched result from the PPA threshold.
+ [CVE-2026-109618, CVE-2026-109619]: Avoid state corruption via
patched
On a server where either check fails, run sudo apt update and sudo apt upgrade, then restart php8.1-fpm so no worker keeps the old code in memory. Skip the old 'php8.1*' glob trick, because the apt front end no longer expands package wildcards.
Run PHP 8.1 beside a supported PHP
Each PHP branch on Ubuntu has its own FPM service, config tree and socket, so 8.1 and a supported branch live on one server without fighting. This is how you get off 8.1 without a big-bang cutover. You install the newer branch next to it, then move one site at a time by changing a single line in its web server config. On the 24.04 lab server we added PHP 8.3 next to 8.1.
On 24.04 the commands below work as shown. On 22.04 they don’t, because the jammy archive has no php8.3-fpm, so you’d need the Ondřej PPA there too. Adding it on 22.04 also replaces the Ubuntu 8.1 build on the next upgrade, since the PPA publishes 8.1.34-9+ubuntu22.04.1+deb.sury.org+1 for jammy and that sorts above 8.1.2-1ubuntu2.28. From then on, use the PPA threshold in the PHP2Shell check. If you want to stay on the Ubuntu build, test the newer branch on a separate 24.04 host instead.
sudo apt install -y php8.3-fpm php8.3-cli
ls -l /run/php/
systemctl is-active php8.1-fpm php8.3-fpm
Two sockets and two active services come back. The php command, though, now runs 8.3, because update-alternatives picks the highest priority (83 beats 81) while it is in auto mode.

That silent switch breaks your cron jobs and deploy scripts that call plain php and expect 8.1. Pin the CLI back to 8.1 until the app moves, or call php8.1 by its full name in those scripts, which is the safer habit anyway.
sudo update-alternatives --set php /usr/bin/php8.1
In Nginx, the PHP version a site runs is the socket in its fastcgi_pass line. We tested that with a small site file on a server with no other sites. On a box that already hosts sites, keep the default site, drop default_server and give the block its own server_name, or it takes over port 80. Install Nginx if it isn’t there yet, then create the file.
sudo apt install -y nginx
sudo vim /etc/nginx/sites-available/legacy
Add this server block, with the docroot and socket for the 8.1 app.
server {
listen 80 default_server;
root /var/www/legacy;
index index.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
}
Enable it in place of the default site, add a one-line probe page, and test the config before you restart Nginx. The rm of the default site is for a fresh server only, so leave it out on a box that already serves sites.
sudo mkdir -p /var/www/legacy
echo '<?php echo PHP_VERSION, " ", PHP_SAPI, PHP_EOL;' | sudo tee /var/www/legacy/index.php
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/legacy /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl restart nginx
sleep 2; curl -s http://127.0.0.1/
The sleep 2 is there for a reason. Our first run used a reload and curled straight after it, and it still got the “Welcome to nginx!” page, because systemctl reload returns before the old workers finish and hand over. With a restart and the pause, the page answers from PHP 8.1 through FPM.
8.1.34 fpm-fcgi
Moving the site to 8.3 is then a one-word change in fastcgi_pass, and moving it back is the same change in reverse. This is the switch we ran.
sudo sed -i 's/php8.1-fpm.sock/php8.3-fpm.sock/' /etc/nginx/sites-available/legacy
sudo nginx -t && sudo systemctl reload nginx
sleep 2; curl -s http://127.0.0.1/
We then ran the same sed in reverse to flip back, and the probe followed the socket each time.

That rollback path is the main reason to run both branches side by side, since a failed 8.3 test costs you one reload. Delete /var/www/legacy/index.php once you have read it. For full Nginx and Apache virtual host setups, see Nginx with PHP-FPM on Ubuntu or the hosting section of the PHP 8.2 guide.
Add the extensions your app needs
Extensions follow the php8.1-<name> pattern on both sources, but the catalogue differs. Running apt-cache pkgnames php8.1- | wc -l counted 65 packages in the 22.04 archive and 90 in the PPA on 24.04. Install only what your app actually requires, since every module loads into each FPM worker. A typical Laravel or WordPress app needs this set.
sudo apt install -y php8.1-{mysql,xml,mbstring,curl,zip,intl,gd}
Check that the modules loaded. On our 22.04 server the filtered php -m list showed every one of them.
php -m | grep -E 'mysqli|pdo_mysql|xml|mbstring|curl|zip|intl|gd'
The FPM workers only load new modules after a restart, so run sudo systemctl restart php8.1-fpm before you test the app in a browser. The PHP 8.2 guide has the longer module walk-through if your app needs more than this.
Plan the move off PHP 8.1
On 22.04 the clock that matters is Ubuntu’s, not the PHP project’s. Running pro security-status on the lab server said Main is patched “until 2027” without Pro. After that, every PHP 8.1 package on the box needs Ubuntu Pro, which is free for up to 5 machines: esm-infra covers the Main packages such as the CLI, and the --esm-apps view listed the FPM, intl and zip packages as Universe packages covered by esm-apps.

The Ubuntu release cycle page puts the end of 22.04 standard support at May 2027. Use the time before then for the move, in this order.
- Install the target branch on a 24.04 host, or next to 8.1
- Run the test suite with
php8.3orphp8.2 - Read the PHP 8.1 to 8.2 migration notes
- Switch one site’s
fastcgi_passand watch its error log - Remove the
php8.1-*packages when no site uses the socket
Pick the target with its own end date in mind. PHP 8.2 itself loses security support on 31 December 2026, so it’s only a short hop, while PHP 8.3 on Ubuntu runs to the end of 2027 and PHP 8.4 on Ubuntu to the end of 2028. If the same app also runs on Debian, the PHP 8.1 guide for Debian 13 and 12 covers that side. Our call is simple. Keep 8.1 on 22.04 with the Ubuntu build rather than the PPA, prove the app on 8.3 on a 24.04 host where 8.3 is the stock PHP, and move every site there before May 2027.
Doesn’t work. Ubuntu 20.04
After install:
$ sudo apt install php8.0
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package php8.0
E: Couldn’t find any package by glob ‘php8.0’
Please check of repo is configured correctly.
If this is anymore helpful, I won’t even need a brain ^_^
Worked like a champ (April 2022)
Thank you for the clear instructions and easy to follow.
Thanks, sir.
It has worked well for me!
Well this works well…
awesome
thanks for this post very helpful,
I have a question when i run php –module , i am getting this warning :
PHP Warning: PHP Startup: Unable to load dynamic library ‘zip.so’ (tried: /usr/lib/php/20210902/zip.so (/usr/lib/php/20210902/zip.so: undefined symbol: zip_register_cancel_callback_with_state), /usr/lib/php/20210902/zip.so.so (/usr/lib/php/20210902/zip.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
and the zip extension doesn’t appear in list of installed modules
Try creating the following script and check if zip is loaded.
phpinfo();
Hallo, today (since June 2023) the Ondrej Sury PPAs are not anymore available for Ubuntu 18.04 !!!
Its EOL so the PPA closed 🙁
I didnt find any backup, they just vanished!
I wanted to install php8.1-mbstring, and noticed that there is nothing in the sources, so first tried to uninstall all php8.1 with the result, that now all is missing, not only mbstring 🙁 🙁
I am still on 8.0 though, and 8.2 I also still have, but 8.1 is gone.
Any clue how to get the ppa back, maybe from wayback?
Thanks for hints.
franks
Please use https://computingforgeeks.com/install-php-8-7-on-ubuntu-18-bionic-beaver/