Ubuntu: removing PHP from ppa:ondrej/php and switching to the Ubuntu version

The PPA ppa:ondrej/php by Ondřej Surý is the best-known source for newer or older PHP versions on Ubuntu. After a do-release-upgrade, however, it often no longer fits: the upgrade disables the package source, the installed PHP packages stay at the old version – and stop receiving updates. If the new Ubuntu release ships a current PHP version anyway, switching back to the official packages is usually the cleanest solution.

1. Take stock

php -v
dpkg -l | grep -E '^ii\s+(php|libapache2-mod-php)' | awk '{print $2, $3}'

Packages from the PPA can be recognised by version numbers containing +ubuntu…+deb.sury.org. Where an installed version comes from is also shown by apt policy php8.1-common (adjust the version). It is also worth noting down your own changes in /etc/php/<version>/ (e.g. php.ini, PHP-FPM pool configurations) – they have to be carried over to the directory of the new version later.

2. Re-add the PPA and remove it with ppa-purge

ppa-purge resets all packages from a PPA to the version from the Ubuntu repositories, or removes them if there is no counterpart there. For this the PPA must be enabled – so after a release upgrade, add it again first:

sudo add-apt-repository ppa:ondrej/php
sudo apt install ppa-purge
sudo ppa-purge ppa:ondrej/php

Before doing anything, ppa-purge shows which packages will be downgraded or uninstalled. Afterwards the package source is removed again as well. More on PPAs in general can be found in the article Ubuntu: removing a PPA.

3. Install PHP from the Ubuntu repositories

The metapackages without a version number always install the PHP version that belongs to the respective Ubuntu release. Pick the extensions you need – this list covers WordPress, Nextcloud and most typical web applications:

sudo apt update
sudo apt install php php-cli php-fpm php-common php-mysql php-zip php-gd \
  php-mbstring php-curl php-xml php-bcmath php-intl

4. Switch the web server to the new version

Apache with mod_php: disable the old module and enable the new one (adjust the version numbers to yours; ls /etc/apache2/mods-available | grep php shows the available ones):

sudo a2dismod php7.4
sudo a2enmod php8.3
sudo systemctl restart apache2

Nginx or Apache with PHP-FPM: change the socket in the web server configuration to the new version, e.g. from /run/php/php7.4-fpm.sock to /run/php/php8.3-fpm.sock, then enable the new FPM service and reload the web server:

sudo systemctl enable --now php8.3-fpm
sudo nginx -t && sudo systemctl reload nginx

Now carry over your own settings from step 1 (e.g. memory_limit, upload_max_filesize) to /etc/php/8.3/apache2/php.ini or /etc/php/8.3/fpm/php.ini.

5. Clean up and test

sudo apt autoremove --purge
php -v
php -m

Finally, open your web applications and keep an eye on the web server’s error log. If a directory of the old version with leftover configuration remains under /etc/php/, it can be removed once everything is running.

Or stay with the PPA after all?

The PPA is well maintained and perfectly legitimate if you need a specific PHP version that Ubuntu does not provide – for an older application, say. In that case simply run sudo add-apt-repository ppa:ondrej/php again after the release upgrade so that the package source matches the new Ubuntu release, followed by sudo apt update && sudo apt full-upgrade.

Originally published in 2022 after the upgrade to Ubuntu 20.04, revised in December 2026. Sources of the first version: askubuntu.com, computingforgeeks.com.