Current Location: Home> Latest Articles> Complete Guide to Uninstalling PHP on Linux Systems

Complete Guide to Uninstalling PHP on Linux Systems

gitbox 2025-06-24

PHP is a core component in many web applications running on Linux systems. However, there are scenarios where you might need to remove PHP from your server, such as preparing for an upgrade or when PHP is no longer needed. This guide walks you through the process of properly uninstalling PHP and related components from various Linux distributions, ensuring a clean and safe removal.

Why You Might Need to Uninstall PHP

You may consider removing PHP from your system for the following reasons:

  • Upgrading to a newer version of PHP
  • Your project no longer requires PHP
  • To clean up the system and free up resources

Pre-Uninstallation Checklist

Before uninstalling, make sure to:

  • Back up your website files and databases to avoid data loss
  • Check your current PHP version using php -v

How to Uninstall PHP on Different Linux Systems

Here are the appropriate commands based on your Linux distribution:

Ubuntu / Debian Systems

On Debian-based systems, use the following command to remove PHP and all associated modules:

sudo apt-get purge php*

This will completely remove PHP and any installed PHP modules.

CentOS / RHEL Systems

For CentOS or RHEL users, execute the following command:

sudo yum remove php*

This will delete PHP along with all related components.

Uninstalling a Specific PHP Version

If you have multiple PHP versions installed and only want to remove one, use the appropriate command below:

  • To remove PHP 7.4 on Ubuntu/Debian:
sudo apt-get remove php7.4
  • To remove PHP 7.4 on CentOS:
sudo yum remove php74

Post-Uninstallation Cleanup and Verification

After uninstallation, verify whether PHP has been successfully removed with:

php -v

If the terminal returns “command not found,” PHP has been successfully removed from your system.

Conclusion

Uninstalling PHP on Linux is a straightforward task when using the proper commands for your distribution. Whether you're upgrading, optimizing performance, or simply no longer using PHP, following these steps will ensure a clean removal and help maintain a tidy, efficient server environment.