The hot new buzzword might be "cloud computing" but the concept is as old as the Internet. The one thing that has changed recently is the affordability. It used to cost thousands to host your dedicated server out on the net but now with Amazon you can do it for free! In this article I'll be guiding you through the process on how to run a free LAMP server on Amazon EC2. If you're not afraid to spend a little money (less than $20 a month) I'll even show you how to run a full blown domain with Route 53 and SES.
Hosting with EC2
Amazon's Infrastructure as a Service (IaaS) platform is called Elastic Cloud Computing (EC2). This service provides full root level access to a Linux or Windows box of your choice. Amazon has a great offer where you can provision a micro server for free for one year. I'll show you how you can use this to create and run a free LAMP server.
The first thing you'll need to do is create an AWS account, it's free but it does require a credit card on file. AWS uses Amazon's 1-click no questions asked methodology so if you ask for 100 servers you'll instantly have 100 servers (and a crazy bill). It's probably a good idea to sign up for free billing alerts when you get a chance.
Once your logged in, start the AWS Management Console. Now enter the EC2 dashboard and click 'Launch Instance'. Use the classic wizard and select a 64 bit Amazon Linux AMI instance. This is another Red Hat Enterprise 6 rebuild just like CentOS or Scientific Linux but it comes with all the AWS utilities already installed. On the next screen make sure you have t1.micro set as the machine type and keep clicking continue until you get to the create key pair screen. If this is your first EC2 server you'll be required to create an SSH key pair that allows you to login to your machines (you won't be able to login with just a password). Next, on the firewall tab you can setup a "hardware" level firewall that's independent of the OS firewall. For our LAMP server, I recommend creating a new security group and opening TCP ports 80 and 22 and all ICMP ports. Now you can move on to the summary screen and launch your instance. It will take a minute or two to boot but you should see your new machine listed under 'Instances'. If you click on your instance and view the description you'll see it has a randomly assigned IP and DNS entry. These temporary addresses will change at various intervals so they're not much good for long running services. A reserved static IP would be more useful so lets do that next.
EC2 has a cool feature called Elastic IPs. You may reserve as many IPs as you like and assign or unassign them to machines as you see fit. Amazon even provides the first IP for free but will charge you for any additional IPs whether you're using them or not (too bad they don't have IPv6 yet). Go ahead and grab your free IP and then assign it to your EC2 box. After a few seconds this will change the public IP address and auto-generated DNS entry of your box. As a side note, if you power off an instance, Amazon will annoyingly auto unassign that box's elastic IP and you'll have to go back and reassign it at power on.
Now we're ready to SSH into the box and install some software. Fire up your favorite SSH program (or use the Java applet in the management console), make sure your private key is loaded, and connect using your assigned IP or public domain name. Remember, root logins are not allowed so you'll need to login as ec2-user. Now lets install some packages:
sudo yum install php mysql-server
Now lets start them up:
sudo service httpd start
sudo service mysqld start
Finally, lets make sure they start on boot:
sudo chkconfig httpd on
sudo chkconfig mysqld on
Congratulations! You have just setup a new LAMP server without paying a single penny. You should be able to access the default welcome page from any web browser using your server's IP address or public domain name. You may install other software packages if you'd like but I found that RAM is pretty tight on these micro boxes and they don't come configured with any swap space so it's easy to trigger the OOM killer. To squeeze a little more RAM out of the box you can ask Google how to configure a Linux swap file. If you have a nice domain name that you would like to use and a little cash to spend then read on, otherwise you're welcome to start programming (you can find the web root at /var/www/html/).