How to Remove a PHP Version
Once a PHP version reaches End of Life status, any security issues which arise will go unpatched. They can quickly become a major security concern for your server and should be removed completely as soon as possible.
Upgrade Sites
Before removing a PHP version from the server, you should check for any sites on the server still using it and upgrade them to a newer version.
You can view the PHP version for each site at a glance from the server dashboard to quickly identify which sites will need upgrading.
The PHP version can be easily changed from the site’s Setting page.
We recommend testing this change on a temporary copy of the site made using SpinupWP’s Clone Site feature. Testing the change on a temporary clone like this will allow you to investigate and resolve any incompatibilities or error log entries arising from the new version without impacting your production site.
Once you are satisfied that the site is ready for the newer version of PHP, you can delete the temporary site and update the PHP version on the production site.
Remove PHP Version From Server
Now that the PHP version isn’t in use, you are ready to remove it from the server.
To get started, connect to the server using a sudo user.
Once connected, start by listing all the PHP packages for the PHP version you’d like to remove, replacing {PHP_VERSION}
with the PHP version you’d like to remove:
sudo dpkg -l php{PHP_VERSION}* | grep ^ii
For example, to list all the PHP 8.0 packages, you would use:
sudo dpkg -l php8.0* | grep ^ii
You should see a list of packages, similar to the following:
ii php8.0-bcmath 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 Bcmath module for PHP
ii php8.0-cli 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 command-line interpreter for the PHP scripting language
ii php8.0-common 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 documentation, examples and common module for PHP
ii php8.0-curl 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 CURL module for PHP
ii php8.0-fpm 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 server-side, HTML-embedded scripting language (FPM-CGI binary)
ii php8.0-gd 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 GD module for PHP
ii php8.0-igbinary 3.2.14-1+ubuntu22.04.1+deb.sury.org+1 amd64 igbinary PHP serializer
ii php8.0-imagick 3.7.0-3+ubuntu22.04.1+deb.sury.org+1 amd64 Provides a wrapper to the ImageMagick library
ii php8.0-intl 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP
ii php8.0-mbstring 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 MBSTRING module for PHP
ii php8.0-mysql 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 MySQL module for PHP
ii php8.0-opcache 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 Zend OpCache module for PHP
ii php8.0-readline 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 readline module for PHP
ii php8.0-redis 6.0.1-1+ubuntu22.04.1+deb.sury.org+1 amd64 PHP extension for interfacing with Redis
ii php8.0-soap 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 SOAP module for PHP
ii php8.0-xml 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 DOM, SimpleXML, XML, and XSL module for PHP
ii php8.0-zip 1:8.0.30-2+ubuntu22.04.1+deb.sury.org+1 amd64 Zip module for PHP
If you’re happy to remove all the packages in the list as well as their related dependencies, run the following command, again replacing {PHP_VERSION}
with the PHP version you’d like to remove:
sudo apt purge `dpkg -l php{PHP_VERSION}* | grep ^ii | awk '{print $2}'`
For PHP 8.0, it would look like this:
sudo apt purge `dpkg -l php8.0* | grep ^ii | awk '{print $2}'`
To clean up any dependencies that are no longer used, we recommend also running autoremove:
sudo apt autoremove
It’s a good best practice to keep your sites using the most recent Active Support version of PHP. This will not only get you access to the latest improvements and features to the language, but also help you identify hurdles to upgrading early and provide plenty of time to update your site’s code as needed to move it forward to the newest version.