Steps to Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

Steps to Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 16.04

LAMP stack is an open source web platform installed to enable a server to host dynamic websites and web apps.It is named as an acronym of Linux operating system, with the Apache web server. Dynamic content is processed by PHP and site data is stored in MySQL.

Below steps shows how to install LAMP stack on an Ubuntu 16.04 Droplet. First requirement for this is Ubuntu, a Linux operating system.

Initial Requirements

User should have a separate, non-root user account with sudo privileges set up on the server.

Step 1: Install Apache

Apache is the most widely used web server software. We are using Apache server because it is well-documented, and has been in wide use for much of the history of the web.

Ubuntu's package manager, apt allows us to install most software pain-free from a repository maintained by Ubuntu

To install Apache, type the following command into the Terminal:

sudo apt-get update

sudo apt-get install apache2

Using a sudo command, these operations will get executed with root privileges. It will ask for regular user's password to verify intentions.

After entering the password apt will show which package it plans to be installed and how much disk space it will take up. Installation will proceed after pressing Y and hit Enter to continue.


Step 2: Install MySQL

Next, we need to install database system. MySQL is a database management system. It will provide access to databases. It’s also very well-supported by third-party tools, as well as by most web hosts.

To install MySQL, type the following command into the Terminal:

sudo apt-get install mysql-server

During installation, you’ll be prompted to set password for MySQL root user.

After installation it starts automatically. Now database is setup and we can move on.

Step 3: Install PHP

PHP allows us to create dynamic content that interact with databases.  It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server to display.

To install PHP, type the following command into the Terminal:

sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

To enhance the functionality of PHP, we can optionally install some additional modules.

Following command will install more than one module

sudo apt-get install package1 package2 ...


Now LAMP stack is installed and configured.

Step 4: Ensure PHP processing on Web Server

To check whether PHP is configured correctly we can create a basic PHP script.

We can create a PHP file by typing the following command

sudo nano /var/www/html/test.php

This will open a blank file. We need to put a valid PHP code inside the file




Then save and close the file.

In order to test whether web server can display the content correctly, we need server’s public IP address.

Note: To find server’s public IP address you can use the iproute2 tools to get your address by typing this:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'


The address you want to visit will be:


The page that you come to should look something like this:

If this was successful, then your PHP is working as expected!!!!!!!

Now we have installed LAMP stack on Ubuntu  16.04 that will allow you to install most kinds of websites and web software on your server.