Skip to content
STAGE33R

Guides · Server software · updated 3 Dec 2026

How to safely disable or remove an old PHP version on Ubuntu and Debian (CloudPanel too)

Old PHP versions (7.x, 8.0, 8.1) no longer get security fixes, but turning one off breaks every site still running on it. The safe order is: find who uses it, move them, disable it so you can undo it, watch for a week, and only then remove it.

  1. See which PHP versions are installed and running

    Each version has its own php-fpm service and its own pool files.

    ls /etc/php
    systemctl list-units 'php*-fpm*' --no-pager
    update-alternatives --display php | head -n 4   # the version the plain php command runs
  2. Find the sites that use the version

    A site uses a version when its web-server config sends requests to that version's socket or port, or when it has its own pool file. Replace 7.4 with the version you are checking. A version with no web-server reference and only www.conf is not used by any site.

    sudo grep -rEn 'php7\.4' /etc/nginx /etc/apache2 2>/dev/null
    ls /etc/php/7.4/fpm/pool.d/   # anything besides www.conf is a site's pool
  3. Check cron jobs and scripts

    Scheduled jobs and queue workers often call a specific PHP binary and never show in the web-server config.

    sudo grep -rEn 'php7\.4|/usr/bin/php' /etc/cron* /var/spool/cron 2>/dev/null
    ps aux | grep -E '[p]hp7\.4' | grep -v fpm
  4. Move each site to a supported version

    Change the PHP version of every site that uses it, test the site, then repeat the search above until it finds nothing. On CloudPanel, change it per site in the site's settings; CloudPanel's own admin interface does not depend on the php-fpm services of your sites.

  5. If the plain php command uses the old version, switch it

    Without this, scripts and cron jobs that call php keep using the old one.

    sudo update-alternatives --set php /usr/bin/php8.3
  6. Disable first (recommended)

    This stops the service and stops it starting at boot, but keeps every file, so it is undone in one command.

    sudo systemctl disable --now php7.4-fpm
    systemctl is-active php7.4-fpm   # inactive
  7. Watch for a week, then remove

    Look for 5xx errors and failed jobs. When nothing needs it, back up its configuration and remove the packages.

    sudo tar czf ~/php7.4-etc-backup.tgz /etc/php/7.4
    sudo apt-get purge 'php7.4-*'
    sudo apt-get autoremove

Common mistakes

  • Running purge before the last grep: a pool file you forgot is deleted with the package.
  • Removing the version the php command points to: scripts fail with "php: command not found".
  • A custom pool (a name other than www) with no workers is still a configured site: confirm before deleting it.

How to undo it

After disabling: sudo systemctl enable --now php7.4-fpm. After removing: install the version again (on Ubuntu from the ondrej/php repository, on Debian from packages.sury.org) and restore /etc/php/7.4 from your backup.

Sources

Commands are for Debian and Ubuntu unless noted. Test on a copy first and keep a backup: you are responsible for changes on your own systems.