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.
You may consider removing PHP from your system for the following reasons:
Before uninstalling, make sure to:
Here are the appropriate commands based on your Linux distribution:
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.
For CentOS or RHEL users, execute the following command:
sudo yum remove php*
This will delete PHP along with all related components.
If you have multiple PHP versions installed and only want to remove one, use the appropriate command below:
sudo apt-get remove php7.4
sudo yum remove php74
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.
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.