How to Setup a LAMP Server on Amazon EC2

In an earlier post, I explained that I migrated from my regular web host over to Amazon EC2 for the purpose of running my various websites. Here, I will detail how I got up and running and configured with a full blown CentOS 5 LAMP (Linux, Apache, MySql, PHP) server including support for .NET via Mono.

First off, if you are new to Amazon’s Elastic Compute Cloud (EC2) then I highly recommend taking a look at t their Getting Started Guide first.

  1. Signup for Amazon EC2 if you haven’t already done so. The Sign Up for EC2 guide is helpful here.
  2. Launch a new EC2 instance from the AWS Management Console:
    1. I recommend using the community AMI ID ami-48f90621 which is CentOS 5, 64 bit. To select this AMI when launching, click “Community AMIs” and search for the ID. See the screen shot below.
    2. On the Configure Firewall step, create a new security group and add an inbound rule for ports 80 (HTTP) and 22 (SSH).
  3. Connect to your new instance using the ssh client of your choice. Note, you’ll need to use the Key Pair your generated when you launched your instance to connect. When asked for the username enter root. I use PuTTY from Windows and it was a little tricky to get connected but the Appendix: PuTTY helped.
  4. Prepare for software installation. In order to install Mono, you’ll need to add the Novell Mono Repository to yum so the mono packages can be found.
    1. Create the file /etc/yum.repos.d/mono.repo (i.e. nano /etc/yum.repos.d/mono.repo) with the following contents:
      Name=Novell Mono Repository
    2. Optionally, you can run the following command and skip the above step to make things a bit easier:
      wget /etc/yum.repos.d/
  5. Install software packages by issuing the following commands from the shell:
    1. yum install httpd [enter]
    2. yum install php [enter]
    3. yum install mysql-server mysql [enter]
    4. yum install mono* –disablerepo=epel,extras [enter]
    5. yum install mod_mono* –disablerepo=epel,extras [enter]
  6. Start services by issuing the following command:
    1. service httpd start [enter]
    2. service mysql start [enter]
  7. Configure PATH environment variable for mono by running this command: export PATH=/opt/novell/mono/bin:$PATH . To persist this after a system bounce, add the same line to the end of the /etc/profile file.
  8. Test your server by opening a browser and navigating to your “Public DNS” domain (i.e. The Public DNS domain can be found on the properties of your EC2 instance in the AWS Management Console. If you get a page that says “Apache 2 Test Page” you are good to go.

That’s it. You are now up and running with a CentOS x64 LAMP Server capable of running .NET applications. There is obviously more you will want to do depending on your needs but the steps above give you server that is “ready to go”.

  • Chris Kolb

    Great post. I’ve been having trouble wrapping my head around the “community AMI” concept. Perhaps I’m less trusting than the average person, but how do you know that the AMI you pick doesn’t come preloaded with something malicious. I actually found your post by searching for the ami ID that you mention above after seeing it in the list on AWS. How do you and I know that that AMI is legit?

  • bholt

    Chris — That thought has crossed my mind but I’m not really sure of the answer. I suppose there could be malicious configuration in some of these community AMI’s but surely Amazon would remove them if it came to be known. Creating your own AMI or using one of the “official” Amazon AMIs would be a way to ensure this. I haven’t really spent the time to learn how to create custom AMIs and couldn’t find an official Amazon AMI with CentOS, which I prefer.

  • Priyanka

    Thanks Brady, very helpful post..(even for newbies like me)! keep up the good work

  • JR Fent

    Great job! Best instructions I’ve seen yet on setting up a LAMP server on an AWS EC2 instance. Thank yout for taking the time!