Highly motivated Senior Java/JEE Software Developer with 7+ years of solid industry experience. Excellent team player with an experience working in distributed international teams, using Agile/Scrum methodology. Artur has posted 9 posts at DZone. You can read more from them at their website. View Full User Profile

A Free Amazon EC2 Cloud Server Based LAMP

11.14.2011
| 19127 views |
  • submit to reddit

Introduction

In this article I'm going to show you how to create a free Amazon EC2 cloud based LAMP Server and Point your domain to Amazon EC2 Instance.

There are 4 simple steps to do.

  1. Sign up for a 1 year free account from Amazon.
  2. Create a new server from an existing image.
  3. Install Apache, PHP, MySQL.
  4. Point your domain to EC2 Server.

Sign up for a 1 year free account from Amazon

Amazon offers an one year free account for new customers. 
Sign up for the account at the following link: http://aws.amazon.com/free/

Create a new server from an existing image

The free account only allows you to use a micro server.
1. Log into the amazon console. https://console.aws.amazon.com/s3/home
2. Go to the EC2 tab and click Launch Instance.
3. Select Launch Classic Wizard and go to the Quick Start tab and select the following Image Basic 64-bit Amazon Linux AMI 2011.09 (AMI Id: ami-1b814f72).
4. Select a Micro Instance which is free Micro (t1.micro, 613MB) and click on continue.
5. Advanced Instance Options: leave the defaults and click on continue.
6. Instance Properties: leave the defaults and click on continue.
7. Create Key Pair This key pair is important because it is needed to connect to your server. Click on the Create & Download your key pair.
8. Creating A Security Group: this allows you to define the firewall rules for your server. Select default and click on continue.
9. Click on Launch to start the server.

Connect to your Server

1. Download and install putty and puttygen. http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
2. Converting Your Key: Before you can use putty to login you need to convert the .pem key to a .ppk key.
3. Run puttygen. Select load and choose your downloaded .pem file. Click on Save Private key and save the file.
4. Connecting To Server: Run putty and fill in the server name ->Next click on the SSH -> Auth property. Browse to the new .ppk file and select it.
5. Click open. Type ec2-user and enter.
Congratulations, you are logged in...

Install Apache, PHP, MySQL

Now it's time to install apache, php and mysql on our linux.
sudo su
yum update
yum install mysql mysql-server
yum install php php-mysql php-xml php-mcrypt php-mbstring php-cli php-gd httpd

Configure Linux to start apache and mysql automatically after a reboot
/sbin/chkconfig httpd on
/sbin/chkconfig mysqld on

/sbin/service mysqld start
/sbin/service httpd start

Point your domain to EC2 Server

Each EC2 instance has a dynamic IP. With every server restart your instance will have a new IP address, which is a problem for DNS mapping. To overcome this problem Amazon introduced the notion of Elastic IPs. An Elastic IP is a static IP address that belongs to your Amazon account. To receive a new Elastic IP, simply go to Elastic IPs on the EC2 tab, and click Allocate New Address.
Then select the newly assigned IP and click Associate to assign it to your EC2 instance. The Elastic IP should be mapped to your server. Now your server has a new static IP address.

Now it's time to map your domain to your server: just modify your domain’s A record with your domain name registrar to point to the Elastic IP. If you have your domain registered with GoDaddy, you can go to the GoDaddy DNS Manager, select Edit Zone for your domain, and put the Elastic IP in the box provided for the A record.
In some cases you may need to wait up until 24 hours for old DNS records to expire before the domain name successfully maps to your EC2 instance.

That's all, Enjoy your server...

Published at DZone with permission of its author, Artur Mkrtchyan.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)