PHP Developer

My notes and thoughts about Linux, WordPress, PHP and many more.

How to completely remove PHP, MySQL and Apache in Ubuntu 16.04+

Reasons why you would want to do this

  • Local Apache/MySQL/PHP not working after upgrade to Ubuntu 16.04
  • Local Server beyond repair, diagnosing issues takes too much time
  • Simply want to completely remove LAMPP installation in order to have a fresh installation.

Requirements and scope

Important: Please run:

sudo apt-get update

Before you proceed with anything else.

  • Tested in Ubuntu 16.04+, if you are using an older Ubuntu versions. This may not guaranteed to work
  • You want to completely remove PHP, MySQL and Apache in your local server environment
  • This is not designed to removed Nginx installations.
  • This is not tested to work in other operating systems like Mac, Windows or other Linux distributions except Ubuntu.
  • You need to have root access to your Ubuntu local server.
  • Make sure you install this first:
    sudo apt-get install software-properties-common python-software-properties
  • You need git run this uninstall software:
    sudo apt-get install git

Preparations to make before removal

  1. Backup your existing website files and database – make sure you do a dB dump of every site you are working on locally and put them in the safe place like your Desktop or external drive. This uninstallation procedure completely removes your MySQL including all databases! I recommend that you test your backup to make sure it works 🙂
  2. Now you have a backup, closely examine your MySQL database, there might be databases there that are used for sites but you still need it. Make sure you have a backup it also.
  3. In your Ubuntu 16.04 attempt to update to the very latest packages. In the command line run these two simple commands:
    sudo apt-get update
    sudo apt-get dist-upgrade

Complete uninstallation procedures

  1. Clone this repo to your local Desktop:
    git clone
  2. Get inside the scripts directory:
    cd ubuntu-lampp-server-scripts
  3. Make sure installer scripts are executable:
    sudo chmod +x *.sh
  4. Login as root:
    sudo -s -H
  5. Run the LAMPP uninstaller:

  6. Now all you need to accept all conditions there like pressing 'Y' or pressing 'Enter' key. Make sure you answer 'Y' to all command line questions there or press 'Enter' in the command line screen if ask to. When it asks to delete database for phpMyadmin, you can click 'No'. It does not matter anyway since the dB will be deleted in the succeeding commands. Always keep an eye of the uninstallation progress because it will ask for your input.
  7. Once its all completed and back to command line, its required to run the uninstallation script again to completely pending packages. You can do this as many times as possible. But at least twice or thrice is required.
  8. That's it your done 🙂

At this point, you can safely re-install latest PHP, MySQL, Apache again in your Ubuntu 16.04. If something in this tutorial does not work, let me know and I will update the uninstallation scripts.

Featured image credits:

3 thoughts on How to completely remove PHP, MySQL and Apache in Ubuntu 16.04+

  • Hi, thanx but issues when i try to reinstall lamp :
    “ParamĂ©trage de mariadb-common (10.1.37-0+deb9u1) …
    update-alternatives: erreur: le chemin alternatif /etc/mysql/mariadb.cnf n’existe pas
    dpkg: erreur de traitement du paquet mariadb-common (–configure) :
    le sous-processus script post-installation installĂ© a retournĂ© une erreur de sortie d’Ă©tat 2
    Des erreurs ont Ă©tĂ© rencontrĂ©es pendant l’exĂ©cution :
    E: Sub-process /usr/bin/dpkg returned an error code (1)”

    • It seems you are using Maria dB, this tutorial assumes you are using MySQL database. I think it would work if you replace mysql-common with equivalent mariadb-common. But I have not tested this , so I would recommend to get help somewhere else or read other resources. Thanks for dropping by!

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=""> <s> <strike> <strong> 

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