How to Install LAMP in Ubuntu Server 14.04 LTS

This tutorial will explains basic step how to install LAMP (Linux, Apache, MySQL, PHP or Perl) server in ubuntu server 14.04 LTS. The acronym LAMP is derived from first letters of Linux, Apache HTTP Server, MySQL, and PHP/Perl/Python.

  • Linux is a Unix-like and POSIX-compliant operating system. Ubuntu Server is one of popular Linux distributions dedicated for server environment.
  • Apache is a HTTP web server, the most popular in use. It serves webpages when they’re requested by the web browsers. When you type an URL on your web server and press Enter, the pages you see on screen is most likely served by Apache webserver.
  • MySQL is a database management system now owned by Oracle Corporation. It stores and organizes references to the information the webserver needs.
  • PHP is a reflective programming language, which makes it possible for all these different parts to work together.

This tutorial assumes that you have already installed Ubuntu Server 14.04 correctly in you machine, if you need guide basic install ubuntu server 14.04 you can read here

Install and Configure Apache2

First, update ubuntu repository with the following command :

sudo apt-get update

Install Apache2 and all related dependencies with these command:

sudo apt-get install apache2 apache2-utils

Once apache2 installed, modify file /etc/apache2/mods-enabled/dir.conf, with your favorite editor. I’ll used nano command:

sudo nano /etc/apache2/mods-enabled/dir.conf

You should see the following line:

<IfModule mod_dir.c>
       DirectoryIndex index.html index.cgi index.php index.xhtml index.htm

Change to:

<IfModule mod_dir.c>
       DirectoryIndex index.php index.html index.cgi index.xhtml index.htm

Restart apache2 with following command:

sudo service apache2 restart

Now you can check out apache2 is working or not by visiting your server’s public IP address or domain from your web browser ( http://ip_address or If it work you will see the default Ubuntu 14.04 Apache web page, which is there for informational and testing purposes. It should look something like this:

default web page apache2 ubuntu How to Install LAMP in Ubuntu Server 14.04 LTS

Install and Configure MySQL Server

To install Mysql Server package and all related package dependencies run the followong command:

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

During the installation, you’ll be asked to setup the MySQL root user password. This is an administrative account in MySQL that has increased privileges, Enter the password and select [OK].

configuring mysql server 5.5 How to Install LAMP in Ubuntu Server 14.04 LTS

After the mysql server installation complete, you need to run some command for tell MySQL to create database directory structure where it will store its information. You can do this by typing the following command:

sudo mysql_install_db

create database directory structure How to Install LAMP in Ubuntu Server 14.04 LTS

Run the following command, It will be ask you to enter the password for the MySQL root account. Next, it will ask you if you want to change that password. If you are happy with your current password, type “n” for “no”. It also ask you to remove some sample users and databases, disable remote root logins, and load these new rules so that MySQL immediately respects the changes you have made.

sudo mysql_secure_installation

mysql secure installation How to Install LAMP in Ubuntu Server 14.04 LTS

Install and Configure PHP5

To install PHP5 package and all related package dependencies run the following command below. by default ubuntu server 14.04 will installed PHP 5.5

sudo apt-get install php5 php5-mysql php-pear php5-gd  php5-mcrypt php5-curl

Testing PHP5 and MySQL

In order to test PHP script you need to create simple PHP script in directory /var/www/html. in this case I’ll create phpinfo.php:

sudo touch /var/www/html/phpinfo.php
sudo nano  /var/www/html/phpinfo.php

Add the following line into file /var/www/html/phpinfo.php

<?php phpinfo(); ?>

Save and exit ( Ctrl + O, Ctrl + X)

Test the php script you have made from web browser by typing in address bar http://ip_address/phpinfo.php. It will appear like screenshot on below.

Test the php script How to Install LAMP in Ubuntu Server 14.04 LTS

This page basically gives you information about your server from the perspective of PHP. It is useful for debugging and to ensure that your settings are being applied correctly.

Testing MySQL connection with PHP script. Create the file /var/www/html/phpmysql.php then add the following line on below. Replace the password with your mysql root password have made during mysql installation:

sudo touch /var/www/html/phpmysql.php
sudo nano /var/www/html/phpmysql.php
$con = mysql_connect("localhost","root","password");
if (!$con)
 die('Could not connect: ' . mysql_error());
 echo "Congrats! connection established successfully";

Now open web browser and navigate to http://ip_address/phpmysql.php, The page should be appear like screenshot on below:

Test the php mysql script How to Install LAMP in Ubuntu Server 14.04 LTS

The following video created by LinuxScoop and is describes basic steps how to installing LAMP in Ubuntu Server 14.04 LTS. Original Video found here


Now that you have a LAMP (Linux, Apache2, Mysql 5, and PHP5)  installed in Ubuntu Server 14.04. Installing LAMP in ubuntu server 14.04 you can also using single command:

sudo apt-get install lamp-server^


sudo tasksel

Then select [ * ] LAMP Server, It will install all package that needed for LAMP Stack.

Basically, you have installed a platform that will allow you to install web based apps in your server.

Note : This tutorial have been tested on VPS DigitalOcean 512MB

Link Reference:

Tags: #Apache2 #LAMP #MySQL #PHP #Ubuntu Server 14.04 #Web Server

How to Upgrade Ubuntu Server 12.04 to Ubuntu Server 14.04 LTS
How to Upgrade Ubuntu Server 12.04 to Ubuntu Server 14.04 LTS
This tutorial will describes how to upgrade
  • Ronalds

    ffmpeg not supported by this release + could be problems making apache to interpret php.

  • edmarrp

    I did this way, but my Lamp-Server don’t work. The Apache2 page is ok, but the php test isn’t connecting at localhost.

    • Ravi

      In php.ini you should change bind-address = localhost to bind-address = your_ip

      • Ravi

        Sorry, not int php.ini but in /etc/mysql/my.cnf and change the line:

        bind-address = localhost
        to your own internal ip address e.g.
        bind-address =

  • King Shapour

    Fantastic tutarial. Thank you so much for sharing.

  • auchomage

    This was a great help, along with the video – ensured I didn’t go wrong. It works for me thank you.

  • Sebastián GlobalNet

    Hi! iḿ sebastian from Argentina, my question is:
    Why you change
    DirectoryIndex index.html index.cgi index.php index.xhtml index.htm

    for this one:

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

    is the order of index’s files?

  • ZClique

    Excelent tutorial, all works fine to me at DigitalOcean

  • mag

    Excellent, it works.

  • airmi tilahun

    Thanks !! it works …. it helps me so much ……

  • yosvelquintero

    Great work! Thanks;)

Must read×