Installing Apache Server(Lamp) on ubuntu server

Installing Lamp on ubuntu server
30 December 2016

Install Lamp Stack on Ubuntu.

"LAMP" Stack is group of open source softwares where L stands for Linux, A stands for Apache, M stands for Maria DB(MY Sql), P stands for Php. All these open source software installed together let us to host powerful application on server.

In this article we will install LAMP Stack in 3 easy steps.

Step 1:- Install Apache and enable Firewall
Apache is one of the most powerful and mostly widely used open source web server in the world. We can easily install it using Ubuntu default package manager apt.

~/Server $ sudo apt-get update
~/Server $ sudo apt-get install apache2

As we have used sudo command so you will be asked to enter password for root privileges. It will show how much space it will take and will ask to confirm so press Y and press Enter.

Supress Syntax Warning

~/Server $ sudo nano /etc/apache2/apache2.conf

It will open apache2.conf file in the terminal. Navigate to bottom of the terminal and add ServerName your_ip_address
Save the file and close it. After it we have to restart apache2.

~/Server $ sudo systemctl restart apache2

Now to allow incoming web traffic we have to adjust firewall.

~/Server $ sudo ufw allow in "Apache Full"

Now to check everything works ok visit your server's ip address http://your_ip_address. If everything is ok you will see apache landing page. You are all ready for Step 2.

Apache Landing Page

Step 2:- Install MySql Server
After installing apache we are ready for next step which is installing Mysql Server. Mysql is open-source RDBS(relational database management system) where we can store our site information. We can install Mysql Server in two commands.

~/Server $ sudo apt-get install mysql-server

It will be show again how much space it will take. Press Y and the Enter to continue. During the installtion you will be prompted to enter password and reconfirm it. This password is for admin account.
When Everything is done we are ready to run some security script to increase security for Mysql Database.

~/Server $ sudo mysql_secure_installation

Answer Y for yes and any other key for no. We will strongly recommend Y for everything but frankly its your choice. Well we are done with step 2 now to step 3.

Step 3:- Install Php
Now we are ready for our final step. Php is programming language which can runbs scripts and make connection to mysql databse.

~/Server $ sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql php-curl

This will install php and all important dependency we need. Now we want to increase indexing of php scripts so that they are more prefered.For that we have to type following command.

~/Server $ sudo nano /etc/apache2/mods-enabled/dir.conf

We have to move index.php from middle to first. From

DirectoryIndex index.html index.cgi index.php index.xhtml index.htm

to this

DirectoryIndex index.php index.html index.cgi index.xhtml index.htm

Save and Close the file. Now we have to just restart apache and we are all set. And we can do that by typing following commands:-

~/Server $ sudo systemctl restart apache2

If you have are here you can pat your back as you have sucessfully install lamp stack on the server. You can test this by making a php scrip on /var/www/html/ directory. you can do this by typing following commands:-

~/Server $ sudo nano /var/www/html/info.php

And then writing some php code in it. Now when we got to http://your_ip_address/info.php you will see the php code you wrote in action.

By Lakshay Jain

Tags: Cloud