Uninstall LAMP Apache PHP MySQL on Ubuntu 22.04


If for any reason you need to completely uninstall or remove lamp stack PHP, MySQL, and apache 2 on your Ubuntu 22.04 or 20.04 system. So for this, you can type these commands on the terminal: such as sudo apt-get remove –purge php, sudo apt-get remove –purge MySQL, sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common, sudo apt-get autoremove and sudo apt-get autoclean.

In this tutorial, we will show you how to completely remove lamp stack php MySQL apache 2 on ubuntu 22.04 or 20.04 system.

How to Completely Uninstall LAMP Stack Apache PHP MySQL on Ubuntu 22.04

Here are some methods to completely remove LAMP stack Apache 2 PHP MySQL on Ubuntu 22.04:

Approach 1: Stop Apache and MySQL

To uninstall or remove Apache 2 or MySQL server, you must stop first, for this, you can use the command:


//stop apache 2 server
sudo systemctl apache2 stop

//stop mysql server
sudo systemctl stop mysqld

Or if you run these commands without stopping Apache 2 or MySQL server, it will show an error on your terminal window.

Approach 2: Uninstall Apache 2

To remove Apache 2 and its config files, you can use this:


//remove apache 2
sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common
sudo rm -rf /etc/apache2

This will completely remove Apache 2 and its associated config files from your system:

Approach 3: Remove PHP 8.x OR 7.4

Completely uninstall PHP 8.1, 8.2, 8.3 or 7.4 on Ubuntu 22.4, you can use these commands, sudo apt remove –purge php8.x-fpm and sudo rm -rf /etc/php/8.x


//remove php 
sudo apt remove --purge php8.x
sudo apt remove --purge php8.x-fpm
sudo rm -rf /etc/php/8.x

Here X denotes PHP Version.

Approach 4: Uninstall MySQL

To remove completely MySQL and its related packages, files, and created groups, type these commands on the terminal:


//remove mysql and it's extensions
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*

//remove configured files
sudo rm -rf /etc/mysql /var/lib/mysql

//delete the user and group created for MySQL
sudo deluser mysql
sudo delgroup mysql

//Removes unnecessary packages and dependencies
sudo apt-get autoremove
sudo apt-get autoclean

Here is the video tutorial for how to remove lamp stack php MySQL and apache 2 ubuntu 22.04:


Congratulations, you have successfully uninstalled Lamp stack PHP, MySQL, and Apache 2 from your Ubuntu 22.04 system! If you no longer need Lamp Stack, your system should now be clean of all Lamp Stack related files groups, and directories.

Recommended Tutorials



Jaspreet Singh Ghuman

Jaspreet Singh Ghuman


Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.


Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00