best web hosting

How to Install LAMP on Ubuntu 16.04?

Are you looking for a quick and easy guide to host your PHP application on Ubuntu 16.04 Server? then this guide is for you. I will show you how to Install LAMP Ubuntu 16.04, Install MySQL Ubuntu, Install PHP Ubuntu, Install Apache Ubuntu. After following this guide you will be able to quick start hosting of your dynamic PHP applications on the server.


“LAMP” is an acronym for Linux Operating System, Apache Web Server, MySQL Database and PHP to process a dynamic application. Whether you have Dedicated Server, Cloud Server or a VPS they come as an empty server nothing preinstalled on it. In such a situation you will look for simplicity to host your dynamic web application on it. There are many open source and premium web hosting control panels available in the market to save your work by configuring the server to host your application. But in some cases, you prefer not to use hosting control panels and do it yourself by using Linux commands. If you want to Install LAMP Ubuntu 16.04 then you are at right place, follow my below-given step by step guide to accomplish your task.


In order to install Apache, PHP, and MySQL on the server we need a server installed with Ubuntu 16.04 operating system with no configurations done on it. We need a user with sudo privileges in order to proceed further with the installation and configuration of the LAMP on Ubuntu 16.04. However, you can create a user on ubuntu 16.04 but in this guide, we will proceed with the root user of the server you have set up.

Install Apache Ubuntu

Apache initially released in 1995 is free and open source cross-platform web server software, widely used to serve the web pages on the internet. It has gain popularity since last few decades and it has been a best and default web server choice serving almost 40%-45% of active websites.

Installing Apache is quite easy with Ubuntu Package Manager aptUbuntu maintains a package repository and using package manager apt we are going to install Apache on our server.

For simplicity, we will be using commands given below.

First, update the server with latest security package and other updates using the command.

 sudo apt-get update

Sudo has got all the root user privileges. If you are doing SSH to the server using root login credentials then using sudo will not ask you for username and password when you enter the command. But if you are using another user rather than root then it will ask you for the username and password when you enter the command.

Now let us install the Apache 2.0 which is the latest version when I wrote this article.

sudo apt-get install apache2

Once you hit enter after entering this command then you will be asked whether you want to continue or not? Enter to complete the installation of Apache 2.

Now our installation of apache2 has been finished, just to verify whether it has been successfully installed or not, kindly type your IP address in the browser.


You will see the Apache2 Ubuntu Default Web Page.

If you see this page it means that your Apache web server is installed correctly and ready to use.

Install MySQL Ubuntu

As we have successfully installed Apache web server, lets head towards installing MySQL. MySQL is popular database management software. MySQL we will be using to store our website data.

For the installation of MySQL, we again need to use the apt package manager to pull and install MySQL ubuntu software from Ubuntu repository. Before you start the installation of MySQL package make sure you keep your package index up to date by running sudo apt-get update. In our case, we have already updated the server while installing Apache.

According to the MySQL community, minimum RAM required to install MySQL Ubuntu is 2GB, but I have installed MySQL on 1GB RAM and it works fine. My recommendation is to use at least 1GB RAM with Swap file.

sudo apt-get install mysql-server

Again, it will ask you whether you want to continue or not, then press Y. This will start MySQL configuration wizard.

Enter the new password for the MySQL root user, you can also keep this password same as your server root user password.But it is advised to keep your MySQL root user password unique and strong, do not leave it blank.

Re-enter the password


You should remember the password, as we will need this at a time of installing Phpmyadmin.Check out this article How to install phpMyAdmin on Ubuntu 16.04?

Now, we have finished the installation of MySql we can verify it by checking the status of MySQL using the below-given command.

 root@technomania:~# sudo service mysql status
mysql.service - MySQL Community Server</pre>
<pre>Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2017-12-18 14:17:01 UTC; 1min 56s ago
Main PID: 5779 (mysqld)
CGroup: /system.slice/mysql.service
└─5779 /usr/sbin/mysqld

Dec 18 14:16:59 technomania systemd[1]: Starting MySQL Community Server...
Dec 18 14:17:01 technomania systemd[1]: Started MySQL Community Server.

Above you can check that MySQL is installed and is running.

Install PHP Ubuntu

PHP is the server-side programming language and used to process the dynamic content of the website, it is capable of communicating with the MySQL database, retrieve & process the data and hand over to the web server to display it.

We will start the installation of PHP using the Ubuntu package manager apt. Installing PHP takes a few seconds only, but we are going to install some helper packages with PHP like  apache2 mod, MySQL, and mcrypt. 

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

During the installation process, it will ask whether you want to continue or not, press Y and hit enter. This command will install PHP ubuntu package with the helper packages apache2 mod, MySQL and mcrypt.

Above command will install the latest version of PHP, if we need to install other versions we need to mention the php version in the command.

Use the below-given command to install PHP 5.6 version.

sudo apt-get install php5.6 libapache2-mod-php php-mcrypt php-mysql

Check the installed PHP version:

root@technomania:~# sudo php -v
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
 with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

Our server is now ready to serve the dynamic web application, before hosting the application restart the apache server.

sudo systemctl restart apache2

Test the Web Server for PHP Processing

As we have finished installing Apache, MySQL, and PHP we will now test whether our server is able to process PHP files or not. To test the web server for PHP processing we will simply create a phpinfo.php file. Basically, it is the PHP configuration and settings page which is used to ensure that your settings are applied correctly to the server or not.

Our root directory in Ubuntu 16.04 is at var/www/html we will create our phpinfo.php file in root directory. We can create a file using command or we can simply connect our server using WinSCP file manager tool and create a file, I will be using the command to create a file in the root directory.

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

This command will create a blank page named phpinfo.php in the root directory, we need to put the below PHP code in it.


Now the PHP file is created it’s time to access this file through the browser. To access this file you need to use the below-given URL, just replace [server-IP-address] with your server IP address.


After accessing this URL you will probably see this information on the screen.


Now that you have installed the LAMP stack on Ubuntu 16.04, your server is ready to host the PHP websites. You have further options to install different CMS like WordPress, Joomla, or Laravel. In short, using this article you just created a platform to host the different types of websites on your server. Next, you can secure your server by installing SSL certificate on it.

Kindly let me know if you face any issues while following my step by step guide on How to install LAMP on Ubuntu 16.04? You can comment your problems below and I will try to resolve your query as soon as possible. If you like this article don’t forget to share this with your friends & colleagues. If you find my articles are helpful then do subscribe to our newsletters.

Thank you for reading.


best web hosting


Add Comment

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