How to install LAMP server in Ubuntu


Applicable To: Ubuntu, Ubuntu family distributions, Linux Mint, Debian(partial) and derivatives.
Updated: Friday, 04. October 2019 04:46 PM UTC


Overview

Installing LAMP server in Ubuntu follows through a multi-step process. To make this task automated, I have written a script which can install LAMP on Ubuntu and also set up custom sites if specified. This method should work for Ubuntu 13.10/14.04/15.10/16.04/18.04 etc.. and their derivatives (like Linux Mint 17, 18, 19 etc..)

Install the lampi script

wget https://raw.githubusercontent.com/neurobin/lampi/release/lampi
chmod 755 lampi
sudo cp lampi /usr/local/bin

Install LAMP with lampi

sudo lampi -i
That's it. It will install LAMP server in your ubuntu machine and setup a basic website in localhost with the server name localhost and document root in /var/www/html.

Creating a custom site

If you want a site with custom name for it and put your website in an arbitrary place, then you can just set it up with:

sudo lampi -n example.com.local -dr ~/example-site
where example.com.local is your site name and ~/example-site is the document root for this site.

If you want to have https website too, then add a -s flag to the above command:

sudo lampi -s -n example.com.local -dr ~/example-site

Of course, you could do it during the LAMP installation stage too. The following will install LAMP and setup a custom site (with https) for you:

sudo lampi -i -s -n example.com.local -dr ~/example-site

Now visit https://example.com.local or http://example.com.local.

What does this lampi script do?

The lampi script does the following:

  1. Install apache2, mysql, php and optionally phpmyadmin
  2. Set up apaceh2, mysql, php and optionally phpmyadmin
  3. Edit required config files
  4. set up or create custom sites with arbitrary names and document root.