Before starting the LAMP installation you should update your package list. Use this command:

sudo apt-get update

Install Apache:

To install Apache, just enter the command:

sudo apt-get install apache2

Once the installation is completed, you can check the Apache service status with this command:

service apache2 status
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
   Active: active (running) since Tue 2016-04-26 15:56:28 UTC; 1min 4s ago

Now Apache installation is done, and you can upload your website into '/var/www/html/'.

Install MySQL

MySQL is a relational database management system (RDBMS) that runs as a server, providing multi-user access to a number of databases.

To install MySQL, enter this command:

sudo apt-get install mysql-server mysql-client

During the installation you’ll be asked to set your MySQL 'root' user password. Enter your password twice and click 'Ok'.

After that you can verify the MySQL server status by using this command:

service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: en
   Active: active (running) since Sun 2016-04-26 16:02:20 EDT; 4s ago

MySQL is now installed.

Install PHP

PHP is a widely used open-source general purpose scripting language that is especially suited for web development and can be embedded into HTML.

To install PHP (v.7) use this command:

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

Test your PHP version:

php -v
PHP 7.0.4-7ubuntu2 (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.6-dev, Copyright (c) 1999-2016, by Zend Technologies

To test PHP, create a sample “test.php” file in Apache document root folder.

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

Add the following lines:


Press 'Ctrl+X' to save file and exit.

Restart apache service:

sudo service apache2 restart

Navigate to http://<server-ip-address>/test.php. It will display all details of installed PHP (version, build date, extensions, etc).

Install phpMyAdmin (optional):

phpMyAdmin is a free and open source tool written in PHP intended to handle the administration of MySQL database with the use of a web browser.

Install phpMyAdmin with following command:

sudo apt-get install phpmyadmin

Select the Web server that should be automatically configured to run phpMyAdmin. In our case, it is apache2.

The phpMyAdmin must have a database installed and configured before it can be used. This can be optionally handled by dbconfig-common.

Select ‘Yes’ to configure database for phpMyAdmin with dbconfig-common.

Enter MySQL application password for phpMyAdmin twice. Also, if you leave the password field empty, then random password will be generated.

Success! Installation of phpMyAdmin is finished.

In case if phpMyAdmin is not working, please do the following steps.

Edit the Apache config file:

sudo nano /etc/apache2/apache2.conf

Add the following line at the end.

Include /etc/phpmyadmin/apache.conf

Press 'Ctrl+X' to save and exit.

Restart apache service:

sudo service apache2 restart

Accessing phpMyAdmin Web page

Now, you can access the phpMyAdmin console by navigating to
Enter your MySQL username and password which you have set in previous steps, and log in.

Your LAMP stack is ready to use!