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.

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.

mysql_secure_installation

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:

<?php
phpinfo();
?>

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

Avatar photo

Asif Khan

Responsible and proactive professional with more than 13 years of experience in IT systems, open source software applications, DevOps, Linux systems, and cloud operations. My main goals are to automate things, keep them safe, and make sure they are strong. I am very good at planning and building the infrastructure for services that people really want. I was drawn to the fast-paced world of cloud computing because it has resources that can be scaled up or down as needed. One of my best skills is being able to use a lot of different DevOps tools to set up, release management, and microservices ecosystems, as well as for provisioning, orchestration, and configuration management.