5/5 - (4 votes)

Last Updated on August 2, 2023 by Vikash Ekka

How to Uninstall PHP, Apache and MySQL on Ubuntu 20.04 LTS

Ubuntu 20.04 LTS is a popular and reliable operating system used by many web developers and server administrators. While PHP, Apache, and MySQL are essential components for web development, there might be situations where you need to uninstall them from your system. Uninstalling these components correctly is crucial to ensure your system’s stability and to free up valuable resources.

In this article, we will walk you through the step-by-step process of uninstalling PHP, Apache, and MySQL from your Ubuntu 20.04 LTS system.

Also Read

Backup Your Data

Before proceeding with any uninstallation, it’s essential to back up your data to avoid accidental loss. Create a backup of your website files, databases, and any other important data related to PHP, Apache, and MySQL.

First we remove PHP from Ubuntu

To uninstall PHP, execute the following command:

sudo apt remove php

After uninstalling PHP, it’s a good practice to remove any residual configuration files that might interfere with future installations. Use the following command:

sudo apt-get remove –purge php*
sudo apt-get purge php*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-php
sudo apt-get dist-upgrade

Remove php 7.2 from terminal

Suppose if you are removing php7.2 then use the below commands.

sudo apt-get remove –purge php7.2*
sudo apt-get purge php7.2*
sudo apt-get purge `dpkg -l | grep php7.2| awk '{print $2}' |tr "n" " "`
whereis php
sudo rm -rf /etc/php
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-php
sudo apt-get dist-upgrade

Stop Apache, MySQL, and PHP Services

To prevent any conflicts or issues during the uninstallation process, stop the Apache, MySQL, and PHP services. Open a terminal and enter the following commands:

sudo systemctl stop apache2
sudo systemctl stop mysql

Remove Apache2  from Ubuntu

To uninstall Apache and remove its configuration files , execute the following command:

sudo service apache2 stop
sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
sudo apt-get autoremove

Removing MySql from Ubuntu

To uninstall MySQL and and remove its configuration files, execute the following command:

sudo apt-get remove –purge mysql*
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-php
sudo apt-get dist-upgrade

Check for Residual Files

Even after uninstallation, some residual files might still exist. To ensure a clean removal, use the following commands to remove any remaining PHP, Apache, and MySQL-related files:

sudo rm -rf /etc/apache2
sudo rm -rf /etc/php
sudo rm -rf /var/lib/mysql
sudo rm etc/mysql 

Cleaning Up

To optimize your system and free up disk space, perform a system update and remove unnecessary packages:

sudo apt update
sudo apt autoremove

Conclusion

Uninstalling PHP, Apache, and MySQL from your Ubuntu 20.04 LTS system requires careful steps to avoid potential issues. Always remember to back up your data before proceeding and stop the services to prevent conflicts. Using the apt package manager, you can easily remove the components, and afterward, it’s crucial to delete any remaining configuration files. Cleaning up your system ensures a fresh start for future installations or other web development setups.

FAQs

Is it safe to uninstall PHP, Apache, and MySQL?

Uninstalling these components is safe, but ensure you have backups of your data and carefully follow the steps to prevent any issues.

Can I reinstall PHP, Apache, and MySQL later?

Yes, you can reinstall these packages whenever needed by following the installation steps.

Will uninstalling MySQL delete my databases?

Yes, uninstalling MySQL will remove the database files. Make sure to back them up before proceeding.

How can I check if PHP, Apache, and MySQL are successfully uninstalled?

You can verify their absence by running commands like php -v, apache2 -v, and mysql --version.

Do I need to restart my system after uninstallation?

It is not mandatory, but you can do so for a clean start.

By Vikash Ekka

Hi All, My name is Vikash Ekka from India. I’m the founder and tech editor of https://www.vetechno.in. I have completed my Graduation in BCA. I love to write technical articles like Windows, Linux & MAC Tutorials, Tips, Tricks, How To fix, Tutorials About Ethical Hacking & Cyber Security Guide, and Software Review. Currently, I have been working as an IT professional since 2018.

Leave a Reply

Your email address will not be published. Required fields are marked *