PHP Developer

My notes and thoughts about Linux, WordPress, PHP, WPML, Toolset 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

  • 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.

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:

Complete uninstallation procedures

  1. Clone this repo to your local Desktop:
  2. Get inside the scripts directory:
  3. Make sure installer scripts are executable:
  4. Login as root:
  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: https://www.youtube.com/channel/UCNnUnr4gwyNmzx_Bbzvt29g

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 class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">