How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04 in AWS EC2 instance

[norebro_social_networks icon_layout=”boxed”]


This turorial will help people who wants to own their own web server to experiment and also to host their own website without cost on AWS. This will also show how to setup LAMP stack environment on AWS EC2 instance and how to deploy web applications on AWS.

A LAMP stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term actually is an acronym which represents Linux operating system, with Apache Web server. The site data will be stored on MySQL database, and dynamic content is processed by PHP.


Before you begin with this tutorial, you should sign up for a new AWS account with verification of your credit card information and billing information. You won’t be charged anything for usage but for verification, you will be charged $1 and it will be refunded back again.

Step One — Launching AWS EC2 Instance

Once you signed as a new AWS user you have to sign in and access aws EC2 console. You have to launch a new EC2 instance. So follow up the steps provided in the video or follow below steps.

  • Click on launch  instance
  • Select Ubuntu 14.04 64bit OS
  • Select t2.micro instance which is only available for free tier
  • Just leave the next step same
  • Add storage step same
  • No need for any tags
  • Configure Security groups SSH, HTTP to access instance later
  • Click on launch  it will ask to create new key pair which will be used later to access using SSH
  • Save the key in a known place

It will take some time to initialize EC2 instance

Step Two — Accessing EC2 Instance using SSH

Now once we launched a new EC2 instance we have to access it using SSH. To access using SSH in Windows and MAC.

In Windows, we need Putty and Putty Gen tools. Putty gen will be used to convert pem public key which we downloaded to a private key as a ppk file. Putty will be used to access instance using ppk file.

Get IP address and Public DNS of your EC2 instance. We need both to access using SSH.

Open Putty tool give IP address, port 22 and also load ppk file using SSH->Auth in the left side. Then click on connect you will be asked to connect in a popup if you are connecting first time say Yes.

Username: ubuntu

You are successfully accessed your EC2 instance.

In MAC you can connect using terminal or tool name VSSH. VSSH is a tool same as Putty but it’s for MAC.

ssh -p 22 username@hostname or ssh -p 22 username@ipaddress

It will ask for a password if requires. In our case, it won’t ask.

Step Three — Installing LAMP stack on Ubuntu 14.04

After accessing EC2 instance using SSH. We will start LAMP stack setup on Ubuntu 14.04 step by step.

Installing Apache is the first step. The Apache web server is currently the most popular web server in the world. Which makes it a great choice for hosting a website.

We can install Apache easily using Ubuntu package manager, apt. A package manager allows us to install most software pain-free from a repository maintained by Ubuntu.

For our purposes first, we have to log in as a root user. After that, we have to update all packages up to date then install Apache package.

sudo su

sudo apt-get update

sudo apt-get install apache2

Afterwards, your web server installed. To verify whether it was installed or not access your server using Public DNS URL in the browser. You will get Apache configuration like below.

To access your instance in browser check below.


Now that we have web server up and running, it is time to install MySQL. MySQL is a database management system. Basically, it will organize and provide access to the database where our site can store information.

Again we can use apt command to install MySQL from package manager using below command.

sudo apt-get install mysql-server php5-mysql

It will ask for a password, give a secure password and remember it. We have to give later to access MySQL.

PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connects to our MySQL database to get information and hand the processed content over to our web server to display.

We can again take the leverage from apt system to install our components. We’re going to include some helper packages as well for PHP.  Before installing PHP we have to restart Apache for that you have to use below command.

sudo service apache2 restart
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

After to verify PHP installation go to your server and follow the path using below command.

cd /var/www/html

Here create a new PHP extension file using Vi editor to show PHP configuration using phpinfo function. To know how to create follow below steps.

vi index.php

To insert some code in Vi editor you have to know how to use it. So some basic commands to work on Vi editor in terminal.

To insert some content click i character

Once you wrote your content and wants to save first you have to comet out from insert environment. For that use click on escape button

Now to save use :w

If you don't want to save and wants to quit :q

if you want to save and quit same time :wq

In index.php file, we have to use phpinfo function to show php configuration of our server in the browser.  So use below code for that.

<?php  phpinfo(); ?>

To see PHP configuration in the browser just access your server in the same way how you saw Apache configuration.



Now it’s better to install some PHP helper packages like mod_rewrite, Curl etc.

php5-cgi - server-side, HTML-embedded scripting language (CGI binary)
php5-cli - command-line interpreter for the php5 scripting language
php5-common - Common files for packages built from the php5 source
php5-curl - CURL module for php5
php5-dbg - Debug symbols for PHP5
php5-dev - Files for PHP5 module development
php5-gd - GD module for php5

Now we are done with LAMP stack environment setup. Now to deploy a dynamic web application go to below folder and upload your code.

There are different ways to upload your application either using SVNGitFTP or via Terminal.

For now, I will show how to use Git to deploy your application. To use git first we have to install git using Ubuntu package manager.

sudo apt-get install git

After this, we have to clone the entire repository using git clone command like below.

git clone http://git repository url

To upload database right now we have access using the only terminal for GUI we have to install PhpMyAdmin. We can install PHPMyAdmin using Ubuntu package manager.

sudo apt-get install phpmyadmin apache2-utils

It will ask for Web server choose Apache and in the next step choose No option.

To access PhpMyAdmin in the browser to update our information as a database check below. It will ask for username and password to access.

Username: root


Step Four — Setting up Apache configuration for multiple websites hosting

If we want to host multiple websites then we have to create different Apache configurations for that you have to create Apache configuration files like below.

cd /etc/apache2/sites-available/

vi sitename.conf

<VirtualHost *:80>
    ServerName websitename
    ServerAlias www.websitename
    DocumentRoot /var/www/html/foldername
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

After this, we have to enable the newly created Apache configuration file for a new website using below command.

sudo a2ensite sitename.conf

Once it’s done we have to restart Apache so that changes will be reflected, for that use below command.

sudo service apache2 restart

Now we are successfully setup LAMP stack environment on Ubuntu 14.04 in AWS EC2 instance and also deployed web applications.

For video tutorial check below.


Comments to: How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04 in AWS EC2 instance

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

    Attach images - Only PNG, JPG, JPEG and GIF are supported.

    Stay connected




    Recent Comments

      Recent Posts

      Recent Comments