In this guide, we're going to set up a Ubuntu based LAMP server on Amazon Elastic Compute Cloud (EC2). If you are a starter with Amazon EC2, do have a look in my get started guide first before going through with this. You need to first setup an Amazon Web Services (AWS) account and learn how to run and save an instance using ElasticFox and puTTY.
I'm going to use one of the base install Ubunty Hardy AMI created by alestic as the Linux foundation. Start up ElasticFox and in the available Machine Images (AMIs) list, select the base Ubuntu Hardy AMI with ID ami-6a57b203 (alestic/ubuntu-8.04-hardy-base-20080517.manifest.xml), and select Launch Instance(s) of this AMI.
Make sure that you've created a keypair for SSH authentication. If not, have look at the get start guide here. Select the appropriate keypair in the next window, and launch the instance. It may take a few minutes for the instance to run (keep refreshing the Your Instances section).
Once the instance state changed to running, SSH to the instance's public DNS as shown below using puTTY.
You should see something like the window below.
On your instance's command shell, enter the following command to begin installation of the LAMP server, and follow through the on screen instructions.
sudo tasksel install lamp-server
Once that is completed, let's enable mod rewrite to support pretty URL.
Let's first update the apt-get application
Install phpmyadmin with the following command.
apt-get install phpmyadmin
You need at least one text editor application. My favorite one in Linux is emacs. Use the following command to install emacs.
apt-get install emacs22
To setup phpmyadmin under apache all you need to do is include the following line in /etc/apache2/apache2.conf
If you use emacs to edit the file, use the command below to open the file in the text editor
Make the necessary changed in emacs, the use Ctrl X-S to save the file, and then Ctrl X-C to close.
This is optional, but I use php curl library in some of my work. So I would like to install the library using the following command
apt-get install php5-curl
Now, we can restart apache.
Let's try out our newly installed webserver and phpmyadmin. Get your instance public DNS, and append phpmyadmin at the end. Open the address in your web browser. For example
Congratulations!!! Your LAMP installations is working if you can see the welcome page of phpmyamin. You can use phpmyadmin to manage your mySQL database (add users, create databases etc). Just remeber your mySQL root password that you specified during the installation.
Lastly, you need to save your LAMP instance and create your own machine image (AMI). Refer to the getting started guide if you don't know how to do this.
If you would like to go further by configuring a LAMP cluster with load balancer, have a look at my cluster with load balancer guide here.