Remove LAMP in Ubuntu

The most popular post on this site is the one showing how to install a LAMP server on Ubuntu. Once you’re done developing your websites on your computer, you may want to remove the LAMP server from your Ubuntu installation. Actually, you probably want to leave the Linux part and only remove the AMP part, (Apache, MySQL, php).

I’ve done a post previously that shows how to do this in several steps, but I wanted to come up with a more automated way. So I came up with this one-liner that will remove Apache, MySQL, php, and phpMyAdmin from your Ubuntu system.

Warning: this command will uninstall the packages from your system without asking for confirmation.

[term]dpkg -l *apache* *mysql* phpmyadmin | grep ^ii | awk ‘{ print $2}’ | xargs sudo apt-get -y purge –auto-remove[/term]

If you’re a bit unsure about doing this and you only want to see a list of packages that will be removed, just leave off the end portion from the last pipe onward, like this.

[term]dpkg -l *apache* *mysql* phpmyadmin | grep ^ii | awk ‘{ print $2}’ [/term]

14 thoughts on “Remove LAMP in Ubuntu

  1. TeenDev

    Nice, not only did it remove LAMP, but it also got rid of KDE when the usual command to remove it wasn’t working. Sometimes side-effects are useful 🙂

    Reply
    1. Linerd Post author

      You’re right! I just tried it on Kubuntu 12.04 and it happened to me. It’s easily fixed with:
      [term]sudo apt-get install kubuntu-desktop[/term]
      Apparently kubuntu-desktop has some MySQL dependencies. After reinstalling it everything seems to be fine. All of my other software is still there.

      Reply
  2. mahfud

    -may i delete every folder like’s apache2, php5, mysql, and phpmyadmin?
    i was panic and i do that.. and my lamp was error.. they did’nt work well.. 🙁
    can you give some guide,, how to reinstall my lamp ?

    thanks

    Reply
  3. Willow Wright

    I am running Ubuntu 10.04 under Virtual Box on a MAC Host. I have attempted to do a LAMP installation per instructions found online. I have successfully installed everything but the PHPMyAdmin. Something is wrong with the installation, but I have no way of knowing what it is. The command line instructions for the install, were clear, the process just wouldn’t complete. And I’ve tried to go back and re-install PHPMyAdmin several times, now it tells me there’s nothing to change or update, but I cannot access PHPMyAdmin in a browser, so it was obviously unsuccessful.

    I want to uninstall JUST the PHPMyAdmin and try again. Can you give me a line of code that would do that?

    Thanks, WCW

    Reply
  4. Timothy

    This would be better in a for loop (eliminating the need for xargs):
    for pkg in `dpkg -l *apache* *mysql* phpmyadmin | grep ^ii | awk ‘{ print $2}’`; do apt-get -y purge –auto-remove $pkg; done;

    Reply
    1. Linerd Post author

      I gave your command a try. It works as long as I add a sudo to the apt-get command so it looks like this:
      [term]for pkg in `dpkg -l *apache* *mysql* phpmyadmin | grep ^ii | awk ‘{ print $2 }’`; do sudo apt-get -y purge –auto-remove $pkg; done;[/term]
      What I don’t like about it is that it ends up running apt-get multiple times. apt-get carries some overhead with it, so your command will take longer to execute. I did a little benchmarking to confirm my suspicion. My command takes about 45 seconds to execute on my computer while your version takes about 74 seconds. In the end, it’s not a big deal either way.

      It just goes to show that there are often many ways to do things. I don’t tend to use for loops very often on the command line, so thanks for offering your perspective.

      Reply

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.