Installation of LAMP Stack on Ubuntu

LAMP server is set of free and open source tools that is used to host websites, especially dynamic websites. LAMP server or LAMP stack, is an acronym with

L being Linux, the Operating System,

A being Apache, the Web Server,

M being MySql ( or MariaDB), the Database,

& P being PHP (can also be Perl or Python), the Programming language.

In this tutorial, we will learn to install LAMP stack on Ubuntu machines, we will already discussed about LAMP server installation on CentOS/RHEL machines.

We are here assuming that you have L part covered & have a system installed with Ubuntu OS. We will proceed with installation of LAMP stack on ubuntu & will start with Web server installation.

(Recommended Read: Beginner’s guide for creating LEMP server )


Apache installation

To install webserver i.e. Apache, open terminal & execute the following command,

$ sudo apt-get install apache2

Once the package has been installed, start the apache service & enable it for boot,

$ sudo systemctl start apache2

$ sudo systemctl enable apache2

Now we can test the apache installation. To test the apache installation, open web browser & in the address bar enter the following url,

http://localhost being the server IP address, replace it with your IP address.

lamp stack on ubuntu


MySQL installation

Next thing to install is database, we are using MySql as our choice of database server. To install MySql on Ubuntu machine, run the following command from terminal

$ sudo apt-get install mysql-server mysql-client

During the MySql installation, we will be asked to provide ‘root’ password, provide a suitable password & than confirm it to complete the installation. Once the installation has been completed, start the MySql service & enable it for boot,

lamp stack on ubuntu

$ sudo systemctl start mysql

$ sudo systemctl enable mysql

We can now connect to the database to check the installation, to connect to MySql, use the following command,

$ mysql -u root -p

And than enter the root password that we provided at the time of installation to connect to mysql,

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective


Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.



PHP installation

Dynamic content of a website is processed by PHP, its a general purpose programming language. To install php on the system, execute the following command from terminal,

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

Once the isntallation has been complete, we will test the php. To do that, open

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

& enter the following content to it,




Save the file & restart the apache service,

$ sudo systemctl restart apache2

Now open the browser & enter the following URL,


We should now see the following page with details about the installed PHP,

lamp stack on ubuntu

We know have our LAMP stack on Ubuntu OS ready to use, we can now deploy the dynamic websites on this stack.

If you have come across an issue that needs our help or just want to make some suggestions, please free to use the comment box below.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of you hard earned money:

Linux TechLab is thankful for your continued support.


Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

You may also like...

4 Responses

  1. Amit says:

    Really helpful for beginners, please also post for OpenStack installation

  2. Amit says:

    Also post for WordPress installation for local server

Leave a Reply

Your email address will not be published. Required fields are marked *