How To Uninstall Php In Ubuntu

In this blog post, we will guide you through the process of uninstalling PHP from your Ubuntu system. This might be useful if you want to switch to another version of PHP or if you no longer need it on your machine.

Before we start, it is essential to know the exact version of PHP installed on your system. To do this, open your terminal and enter the following command:

php -v

You will see an output similar to the one below, which displays the installed PHP version:

PHP 7.4.3 (cli) (built: Oct  6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Uninstalling PHP

Now that you have identified the PHP version installed on your system, you can proceed to uninstall it. To do this, follow the steps outlined below:

  1. First, update the package lists for upgrades and package changes:
sudo apt update
  1. Next, remove the PHP package, replacing “7.4” with the version number you identified earlier:
sudo apt remove --purge php7.4

If you have additional PHP modules installed, you can remove them using the following command, replacing “7.4” with your PHP version number:

sudo apt remove --purge php7.4-*
  1. Once you have removed the PHP package and its associated modules, perform an autoremove to clean up any unnecessary dependencies:
sudo apt autoremove

That’s it! You have successfully uninstalled PHP from your Ubuntu system. If you want to reinstall PHP or install a different version, you can follow our guide on How to Install PHP on Ubuntu.