Tidbits on software development, technology, and other geeky stuff

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: 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.

On the Configure Firewall step, create a new security group and add an inbound rule for ports 80 (HTTP) and 22 (SSH).

  1. 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.

  2. 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.

    • Create the file /etc/yum.repos.d/mono.repo (i.e. nano /etc/yum.repos.d/mono.repo) with the following contents. Optionally, you can run the following command and skip this step to make things a bit easier: wget /wp-content/uploads/mono.repo /etc/yum.repos.d/
      [novel]
            Name=Novell Mono Repository
            baseurl=http://ftp.novell.com/pub/mono/download-stable/RHEL_5/
            enabled=1
            gpgcheck=0
  3. 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]
  4. Start services by issuing the following command:

    1. service httpd start [enter]
    2. service mysql start [enter]
  5. 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.


  6. Test your server by opening a browser and navigating to your “Public DNS” domain (i.e. http://ec2-00-00-00-000.compute-1.amazonaws.com). 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”.

Discuss on Twitter