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.

Highlighting the PHP Version column in the Site index on the SpinupWP Server Dashboard

The PHP version can be easily changed from the site’s Setting page.

Highlighting the form field used to select a specific PHP version for a site on the SpinupWP Site Dashboard

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 amd64        Bcmath module for PHP
ii  php8.0-cli amd64        command-line interpreter for the PHP scripting language
ii  php8.0-common amd64        documentation, examples and common module for PHP
ii  php8.0-curl amd64        CURL module for PHP
ii  php8.0-fpm amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php8.0-gd amd64        GD module for PHP
ii  php8.0-igbinary   amd64        igbinary PHP serializer
ii  php8.0-imagick    amd64        Provides a wrapper to the ImageMagick library
ii  php8.0-intl amd64        Internationalisation module for PHP
ii  php8.0-mbstring amd64        MBSTRING module for PHP
ii  php8.0-mysql amd64        MySQL module for PHP
ii  php8.0-opcache amd64        Zend OpCache module for PHP
ii  php8.0-readline amd64        readline module for PHP
ii  php8.0-redis    amd64        PHP extension for interfacing with Redis
ii  php8.0-soap amd64        SOAP module for PHP
ii  php8.0-xml amd64        DOM, SimpleXML, XML, and XSL module for PHP
ii  php8.0-zip 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.