Build an Amazon EC2 Linux Instance

AWS Security Group

  1. Login to the AWS Management Console in
  2. Create the following Security Group under Amazon EC2
    Group Name: Web Server
    Description: Web Server Environment
    Enable SSH for Source Network
    Enable HTTP for Source Network
    Enable HTTPS for Source Network

    Replace with the public network IP for you machine accessing the EC2 instances

Create Key Pairs to access EC2 Instance

  1. Log in to the AWS Management Console in
  2. Create the following Key Pairs under Amazon EC2
    Key Pair Name: webserver
  3. Save all the key files in a secure place

Building Amazon Linux AMI (Amazon Linux AMI)

  1. Sign in to the AWS Management Console in
  2. Select Amazon EC2 -> Launch Instance
  3. In Quick Start, select Basic 64-bit Amazon Linux AMI 1.0 (AMI Id: ami-38c33651)
  4. In Instance Details, select
    Availability Zone:  Put all your EC2 instance in the same zone
    Instance Type: Pick micro for experimental purpose
    Launch Instances
  5. Select webserver for the key pairs
  6. Select Web Server for security group
  7. Create a new Elastic IP (if none is available) and associate it to the instance
  8. Select the newly created EC2 instance and take a note on the public IP needed to access the EC2 instance later

Access Amazon EC2 instance in Windows using Putty

  1. Download Puttygen from
  2. Run the puttygen executable
    1. In puttygen, click load
    2. Next to the File name box, select All Files and pick the webserver key pair generated in previous step
    3. Click Save private key
  3. Access EC2 Instance
    1. Run Putty
    2. Enter the EC2 instance public IP address
    3. Select Connection -> SSH -> Auth & click Browse the .ppk key just generated
    4. Click Open
  4. Login as ec2-user

Using SSH to access EC2

Access by SSH

ssh -i c:/path/to/webserver.pem -l ec2-user

Remote copy

scp -pr -i c:/path/to/webserver.pem ec2-user@ .

Install Apache, PHP and MySQL on Amazon Linux

  1. Putty to the new instance with the webserver.ppk
  2. Login as user "ec2-user"
    sudo yum update

To install a LAMP stack

sudo yum install mysql-server mysql
sudo yum install httpd mod_ssl
sudo yum install php

To build some additional PHP components, a gcc compiler may be needed

sudo yum install gcc

Many tools we used required Java and Tomcat Server

sudo yum install java-1.6.0-openjdk-devel
sudo yum install tomcat6

Auto Start MySQL and Apache on EC2 Amazon Linux

sudo /sbin/chkconfig --levels 235 mysqld on
sudo /sbin/chkconfig --levels 235 httpd on
sudo service mysqld start
sudo service httpd start

Secure MySQL on EC2 Amazon Linux

sudo /usr/bin/mysql_secure_installation

Remove anonymous user, remote access for root and testing DB

EBS Storage

Install XFS support

sudo yum install xfsprogs
grep -q xfs /proc/filesystems || sudo modprobe xfs
  1. Create a EBS Volume in AWS Management Console
    1. Select Amazon EC2 -> Volumes
    2. Click Create Volume
    3. Size = The size you need
    4. Availability Zone = Must be the same zone as your EC2 instance
  2. Attach the volume to the instance
    1. Select the new volume and click Attach Volume
    2. Name the device /dev/sdh
  3. Create and mount a file system
    sudo mkfs.xfs /dev/xvdh
    sudo mkdir /data
    sudo mount /dev/xvdh /data -o noatime

    The Current Amazon AMI mistaken name sdh as xvdh

    sudo vi /etc/fstab
    /dev/xvdh       /data   xfs    noatime 0       0

Setup a Virtual Host

  1. Edit a Virtual host file
    sudo vi /etc/httpd/conf.d/vhosts.conf
  2. Add
    NameVirtualHost *:80

Changing timezone

Change to Pacific timezone

cd /etc
sudo mv localtime
sudo ln -sf /usr/share/zoneinfo/US/Pacific localtime

Adding monitoring tool

Adding monitoring tool like iostat

sudo yum -y install sysstat