How to completely reset an Apache instance in Ubuntu

While experimenting with mod_python, I ended up completely hosing my local Apache installed. I had the configuration files in a bad state, so I thought I would just drop all of /etc/apache2, remove Apache, and re-install it. But once that happened, /etc/apache2 wasn’t remade! When I tried to start or stop Apache, it spat back:

1
.: 44: Can't open /etc/apache2/envvars

Oh right, thanks… So here’s what I did to erase Apache’s memory of my mistakes:

  • Find and drop all Apache packages:
    1
    2
    sudo dpkg --get-selections | grep apache
    sudo apt-get remove --purge apache2 apache2-mpm-worker apache2-threaded-dev apache2-utils apache2.2-common libapache2-mod-python libapache2-mod-python-doc libapache2-mod-wsgi
  • Re-install Apache:
    1
    sudo apt-get install apache2 libapache2-mod-python libapache2-mod-wsgi libapache2-mod-python-doc

After this, all the configuration files were back, and I had a default Apache install.

Share and Enjoy:
  • email
  • LinkedIn
  • Slashdot
  • StumbleUpon
  • Technorati
  • Netvibes

Post to Twitter Post to Delicious Post to Digg Post to Reddit

Possibly Related (no promises):

  1. Quick tips for NVIDIA and ATI graphics configuration repairs on Ubuntu
  2. 64-bit Ubuntu: Not a problem
  3. Permanently remember password for gksudo

Related posts brought to you by Yet Another Related Posts Plugin.

This entry was posted in CLI and tagged , , . Bookmark the permalink.

27 Responses to How to completely reset an Apache instance in Ubuntu

  1. Moos says:

    Would have “dpkg-reconfigure apache2″ worked?

  2. victortns says:

    i have the same error and i solve the problem with your text, thanks ;)

  3. @Moos: Not sure, will have to try and report next time I fubar Apache :-)

    @victortns: Glad to hear it! That’s exactly why I write this blog :-)

  4. lohitha says:

    I had the same issue with a corrupted apache installation.
    I could solve it with your suggestions.
    Thanx a lot for the info

  5. Rickey Moore says:

    Thanks!!!!!!!! That saved my bacon. It was brutal and scary though. BUT! I have all of my files back and that is what counts. Thanks! Ric

  6. joseliki says:

    thank you so much!!!! my server it works again ;)

  7. phreakincool says:

    Thanks!

  8. Zet0 says:

    Thx a lot !

  9. Comet says:

    thanks so much for this informative post. I had numerous problems with my installation, mostly due to deleting the default virtual host entry in webmin. tried reinstalling apache numerous times, but this did the trick PERFECTLY. THANKS A MILLION!

  10. Kallesson says:

    Thank god (well I guess you are god) for this post. Been looking for ages for an easy way to do this!

  11. tmac says:

    Very cool, just saved me a bunch of time on a hosed install.

  12. Jensca says:

    Hi this worked for me, thanks, can i copy to my personaly blog and link to yours?

  13. @Jensca Sure, link away! Glad it helped.

  14. Fatman says:

    I had the same problem. Thanks. Would have taken me ages to guess that.

    Though actually my Apache config wasn’t hosed. I just felt it was “unclean” and I wanted to start over.

  15. Ben Herman says:

    Thanks so much have a box that has been up 151 days now that i thought i would have to take down and reload due to a massive Apache fubar! This tutorial saved the day, and my up time count!

  16. @Ben Herman: Awesome! It’s all about the uptime, baby :-)

  17. Ntropy says:

    Thank you. After hours of failure, this process worked. Truly appreciated.

  18. Pingback: Can’t open /etc/apache2/envvars

  19. Ben Herman says:

    Wanted to let you know I put these instructions up on my blog and posted back to yours giving you credit. Thanks again.

  20. John says:

    You Sir, are a hero.

  21. Malaysia says:

    u r hero bro! TQ VERY MUCH!!

  22. Ganesh says:

    I new to ubuntu, and I m tryong to reinstall apache for 2 days. but u r command did all for me to config apache.
    thx dude!!

  23. Arema says:

    I had exactly the same problem: out of desperation I manually sudo and deleted the directory apache2. And then I was at a lost as to what to do next because installation did not return the config files. Thanks for this posting!

  24. vineet kansal says:

    Thanks a lot…for this information

  25. Trevor says:

    Thanks for posting this! Now I can start off with a clean slate.

  26. Derek says:

    Hey Thanks for that.. I was in the same situation and got apache back up working again.!
    cool.

  27. devasia joseph says:

    great !!! thanks

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>