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 )
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,
192.168.1.100 being the server IP address, replace it with your IP address.
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,
$ 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,
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.
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,
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.