The Linux, Apache, MySQL and PHP (LAMP) stack is used to host websites. The LAMP stack comes with several advantages, firstly, all components is free to use and secondly, get its the job done with minimal hassle. In this tutorial, I will show you how to setup an Amazon EC2 instance with the LAMP stack. As a result of completing this tutorial, you will be able to install your Content Management Software (CMS) and begin building your website on your very own Virtual Private Server (VPS). So, what sets this tutorial apart from the many that are already available? From experience, I have found that most LAMP stack tutorials are not complete. They will explain how to install the software and you’re on your own from there. As a result of completing this tutorial you will have an understanding of:

  • How to setup an Amazon EC2 instance
  • How to connect to your Amazon EC2 instance via Secure Shell (SSH)
  • How to install the LAMP stack
  • How to configure Apache, ready for a website

Before we begin, it is important to point out why you would complete this tutorial. There are many hosting providers that offer a pre-configured solution at a fairly reasonable price. The advantages can be realized when you consider the difference between shared hosting and virtual private hosting. Shared hosting means your website is on the same server as hundreds, if not thousands of other websites. These websites will often share the same IP address and this can be disadvantageous when it comes to SEO. The other main advantage is cost. Amazon is just one of many VPS providers. By looking at their pricing table, you will begin to understand how you can save money on hosting. The third and often forgotten advantage to hosting your website on an Amazon EC2 instance is scaling. The ability to shutdown the instance and reboot a larger instance, in a matter of minutes is priceless. This means, you do not need to start paying for a larger server before you need it. It also means that when it’s time to upgrade, your website will not need to be moved. These are just some advantages of using a VPS service such as EC2.

What you will need

Since writing this post I have made a more details post about creating an Amazon EC2 instance. I suggest you read that post and skip to step 3. 

Step 1: Setup your EC2 Instance

Login to your AWS account and click EC2 in the very top left corner. In the left menu you will see a link that reads ‘Instances’, click it. This is a list of the instances in your account. Click Launch instance and click ‘Select’ next to Ubuntu Server 14.04, or the latest version of Ubuntu. In the bottom right click ‘Next: Configure Instance Details’ and then click ‘Next: Add Storage’. Click ‘Next: Tag Instance’ and select a tag for your instance. You should be on ‘Step 6: Configure Security Group’ where you will select ‘Create a new security group’.

For now, we will only need SSH and HTTP. SSH is already selected so we can click ‘Add Rule’ and on the new drop down select HTTP. The ports for these two protocols will already be selected, you will not be able to change them. Click ‘Review and Launch’ and then click ‘Launch’. A dialogue will appear telling you that you need to select an existing key par or create a new key pair. From the drop down, select ‘Create a new key pair’ and name the key. Save that file to a secure location. Click ‘Launch Instance’ and your instance will begin to launch.

Step 2: Creating a private key

Open PuTTYgen and click ‘Load’. Find the key that you saved from Amazon and select it. Click the ‘Save private key’ button and save the key to a safe location.

Step 3: SSH into your EC2 instance

By now your EC2 instance should be running. If you select it, you will be able to see a description of your instance down the bottom of the page. In this description will be a public IP address. Copy this address and paste it into PuTTY where it says ‘Host Name or IP address’. When you have a domain pointing at your IP address, you will be able to put your domain in this box. Because the EC2 instance does now allow root login with a password by default, we will need to use the key we generated with PuTTYgen. In PuTTY, expand ‘SSH’ and select ‘Auth’. At the bottom of this tab there will be a browse button, click it and select your private key that you generated.

Note: Your private key will have the extension .pem and you will not be able to see the key. Click show all files and select the key.

Click ‘Open’ in PuTTY and a dialogue will appear asking if you want to connect, click Yes.

Login to your server with the username: ubuntu

We are now connected with the user ‘Ubuntu’ which is good. However, this can get pretty annoying because we will need to write side in front of the commands. To change to root user type: sudo su

Step 4: Installing the LAMP stack

To get started type these two commands

sudo apt-get update
sudo apt-get install apache2

Navigate to your IP address and ensure Apache is installed correctly. The image below depicts what your website will look like with Apache installed correctly.

Apache2 installed correctly

Step 5: Install MySQL

We now have the LA components of the LAMP stack and its time for the M. We will again use the apt-get command to acquire and install the software. Run the following command to install MySQL:

apt-get install mysql-server php5-mysql

When promoted to continue, type Y and press enter. The installer will ask you for a password, make sure you choose something very strong. Type the password twice when prompted and press enter after each time. MySQL should finish installing soon after.

Step 6: Install PHP

We now have the LAM and its time for the P. PHP is a language that is used by most CMS, including WordPress. Type the following command to install PHP:

apt-get install php5 libapache2-mod-php5 php5-mcrypt

Step 7: Simple Apache configuration 

We are almost finished! In this step we will configure Apache, ready to start running our website files. To do this, we will make an Apache configuration file and then enable the website.

Move to your sites-available directory with the command:

cd /etc/apache2/sites-available/

Make a new configuration file with your website address and add.conf at the end. For example, if your website is, you will make a new file called with the command:


Inside this file we will need to put some configuration. Copy the following code and replace with your website address. Make sure you omit any http:// or trailing slashes.

ServerAlias *
DocumentRoot /var/www/

RewriteEngine On
RewriteCond %{HTTP_HOST} ! [NC]
RewriteRule ^/(.*)$$1 [R=301,L]

ErrorLog /var/log/apache2/
LogLevel warn
CustomLog /var/log/apache2/ combined

Press Ctrl + x to exit and when prompted type y and hit enter to save the file.

The DocumentRoot /var/www/ component tells Apache where your files are located. This folder will not exist so we will need to make it. To make the folder you would type:

mkdir /var/www/

Note: You will need to modify the folder name to be your website address.

Enable your new website by typing:


You can now put the WordPress files, or any CMS files inside the folder located at /var/www/your folder and navigate to your website

Next articleHow to encrypt text files with Notepad++
I love technology, solving problems and helping others solve problems. My blog is designed to entertain and educate, both myself and my reader.