Installing and managing LAMP server in Ubuntu

Applicable To: Ubuntu, Ubuntu family distributions, Linux Mint, Debian(partial) and derivatives.
Updated: Sun 26 Jun, 2016 GMT

Installing LAMP (Linux, Apache2, Mysql and PHP) in Ubuntu involves running several commands (or installing some softwares from package manager) and modifying config files. In this tutorial I will show you a one liner solution to this problem i.e a single line of command will do all this for you.

Preview

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 etc.. and their derivatives (like Linux Mint 17 etc..)

How to

First install the lampi script:

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

Now to install LAMP:

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.

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 phpmyadmin
  2. Set up apaceh2, mysql, php and phpmyadmin
  3. Edit required config files
  4. set up or create custom sites with arbitrary names and document root.