32

I am having some wierd issues with Apache2 server on my ubuntu server. I believe some configuration files may have been tampered with. What is the easiest way to remove apache2 completely from my server. I am aware of how to install by using

sudo apt-get install apache2

but, I just want to make sure I completely remove apache2.

4 Answers4

80

First stop your server obviously:

sudo service apache2 stop

Remove apache2 packages and dependencies:

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

If you manually modified or installed stuff, apt might not remove it. Check what's left:

whereis apache2

Have a look whats inside these directories, and if you're confident you want to trash it, manually remove the directories. In my case:

sudo rm -Rf /etc/apache2 /usr/lib/apache2 /usr/include/apache2
Jeroen Ooms
  • 2,269
31

Run the following two commands:

sudo apt-get --purge remove apache2
sudo apt-get remove apache2-common
Paul Gear
  • 4,686
Rajat
  • 3,349
1

These commands will completely remove Apache2, all its configs and logs:

sudo service apache2 stop
sudo apt purge apache2
sudo apt autoremove
sudo rm -rf /etc/apache2
sudo rm -rf /var/lib/apache2
sudo rm -rf /var/log/apache2

Install Apache2:

sudo apt install apache2
sotirov
  • 216
1

I think you can try this out.

APACHE_PKGS=`sudo dpkg --get-selections | grep apache | cut -f 1`

In your Terminal then check to see if it's there:

echo $APACHE_PKGS

Should show something like:

apache2 apache2-mpm-prefork apache2-utils apache2.2-common and many more. Then you run this command:

sudo apt-get remove --purge $APACHE_PKGS
sudo apt-get install $APACHE_PKGS

And you should be good to go.

Zuko
  • 111