Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 5 down vote accepted

Run the following two commands:

sudo apt-get --purge remove apache2
apt-get remove apache2-common
share|improve this answer

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
share|improve this answer
1  
This answer is more complete than the accepted answer. The full sequence of commands is: sudo service apache2 stop sudo apt-get --purge remove apache2 sudo apt-get remove apache2-common sudo apt-get autoremove whereis apache2 apache2: /etc/apache2 sudo rm -rf /etc/apache2 –  Vladimir Tsvetkov Dec 4 '12 at 9:32
    
Great thorough answer. :-0 –  djangofan Dec 4 '12 at 21:57
    
This should be marked as the correct answer. Just had loads of trouble with Apache2 and this saved me from reinstall my OS (Linux Mint 14 MATE). Thanks! –  macmadness86 Mar 1 '13 at 20:48
    
Simply: "sudo apt-get remove apache2;sudo apt-get autoremove --purge" –  diyism Jun 25 '13 at 1:44

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.

share|improve this answer

protected by MadHatter Jul 31 '13 at 14:58

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.