This tutorial details the process how to install LAMP on Ubuntu 16.04 & above machines. LAMP server is a set of free and open-source tools that are 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 discuss LAMP server installation on CentOS/RHEL machines.

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

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


How to install LAMP on Ubuntu 16.04


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

http://192.168.1.100

192.168.1.100 being the server IP address, replace it with your IP address.

How to install LAMP on Ubuntu 16.04


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,

How to install LAMP on Ubuntu 16.04

$ 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

owners.

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

mysql>


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,

<?php

phpinfo();

?>

Save the file & restart the apache service,

$ sudo systemctl restart apache2

Now open the browser & enter the following URL,

http://localhost/test.php

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

How to install LAMP on Ubuntu 16.04

This completes our tutorial on How to install LAMP on Ubuntu 16.04 & above & we now 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

Linux TechLab is thankful for your continued support.