Linux Pathfinder: Linux Howtos and Tutorials

How To Install LAMP Stack On Ubuntu 16.04

How To Install LAMP Stack On Ubuntu 16.04

In this tutorial, we are going to learn how to install LAMP stack on Ubuntu 16.04 server. If we explain LAMP, that would be like Linux, Apache, MySQL, and PHP. Let start with following steps.

How To Install LAMP Stack On Ubuntu 16.04

Install Apache Web

To install Apache, put the below command in terminal.

sudo apt-get install apache2

Now start the service.

sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl status apache2

Go to browser and navigate to localhost or server-ip-address.

Apache Web Page

Install MySQL

MySQL, pronounced either "My S-Q-L" or "My Sequel," is an open source relational database management system. It is based on the structure query language (SQL), which is used for adding, removing, and modifying information in the database.

sudo apt-get install mysql-server mysql-client

Enter the root password twice in the prompt during installation. Start the MySQL service after successful installation.

sudo systemctl status mysql

Sample Output:

$ sudo systemctl status mysql
[sudo] password for asif:
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Sun 2016-09-25 07:40:44 PDT; 36min ago
  Process: 944 ExecStartPost=/usr/share/mysql/mysql-systemd-start post (code=exi
  Process: 920 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exite
 Main PID: 943 (mysqld)
    Tasks: 28 (limit: 512)
   CGroup: /system.slice/mysql.service
           └─943 /usr/sbin/mysqld

Sep 25 07:40:30 ubuntu systemd[1]: Starting MySQL Community Server...
Sep 25 07:40:44 ubuntu systemd[1]: Started MySQL Community Server.

After that, set database administrative “root” user password using below command with the default settings.


Install PHP7

PHP is a script language and interpreter that is freely available and used primarily on Linux Web servers. PHP, originally derived from Personal Home Page Tools, now stands for PHP: Hypertext Preprocessor.

Install PHP7 with below command:

sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi  php7.0 libapache2-mod-php7.0

Check your PHP version in terminal.

$ php -v
PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.8-0ubuntu0.16.04.2, Copyright (c) 1999-2016, by Zend Technologies

Now create a sample “test.php” file in Apache document root folder.

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

Add the following lines:


Restart apache2 service.

sudo systemctl restart apache2

Navigate to localhost/test.php in the browser. Now you can see the PHP details such as version, build date and other modules.

PHP Info Page

Share this article:

Asif Khan's picture
I am an experienced Linux System and Network Administrator with having more than 10 years of experience. My primary responsibilities are to keep up and running Linux system environment, backups important data with scripting and configuration management on AWS Linux server environments. My aim is to help people, in finding their path towards a solution to their problems. Well, I believe helping others can good for both parties, to them and to you as well. That day and today is the day that thousands of people seek help from my website to help people find answers to their questions. I am sure that everyone will get all the answers to their questions related to software and operating system, and this website will help you keep your system updated.

Add new comment


Enter the characters shown in the image.