After you start your AWS EC2 Ubuntu 9.10 Karmic Koala server in 6 mins, if you had to install a full LAMP (Apache PHP and Mysql) stack here is how you do it in under 4 minutes:
Start your command line and execute a command similar to below with your own keypair and Public EC2 DNS name:
Harry-MacBook-/User/Harry/ec2 $ ssh -i id_rsa-ubuntu ubuntu@ec2-185-77-129-63.compute-1.amazonaws.com
Once you are in then type in:
sudo aptitude update && sudo aptitude dist-upgrade
It will ask you for your password and it will ask you if you want to continue with the updates. Type Y and press enter.
It will install a bunch of updates and in a short while it will be done.
At that point you need to execute:
sudo reboot
This will reboot your EC2 instance and you will have to wait less than a minute before you execute your request.
Now we will install Apache, PHP and MySql using the following:
sudo aptitude install apache2 php5-mysql libapache2-mod-php5 mysql-server
During the install it will ask you for a MySql root password. Set it to something you remember just don’t leave it blank.
Test out your webserver by going to the browser and entering the public IP in the browser.
How do you know what is your public IP on EC2? It’s very easy. If you logged into the server using the public DNS ec2-185-77-129-63.compute-1.amazonaws.com, then your IP is 185.77.129.63. So go to your favorite web browser by typing in http://185.77.129.63{as an example in my case}. A page should come up which says “It works”. This is how you know Apache is working.
How do you know if php is working?
Well, you need to try a test php file on your server. For that execute the following on your command prompt:
cd /var/www
- This will take you into the web root.
Here execute the following:
vi test.php
press i at the prompt for inserting and enter the following:
press escape on your keyboard then :wq!. This will save a test.php with the above content.
Now go back to your browser and type in http://185.77.129.63/test.php
You should see a page similar to below:
But now how do we know if MySql is up and running for our website?
This is why we need phpMyAdmin. Here is how you install that:
sudo apt-get install phpmyadmin
Say yes to continue. And voila, its installed in a jiffy!
What is phpMyAdmin? It is a php based interface to your mysql server.
How do you test it? Well lets head back to the browser and type in the following:
http://185.77.129.63/phpmyadmin
And a page like this should show up:
Wow that is great!!! Now how do you get in?
Use the user name: root
And remember the password you had set while installing MySql above? Use that for the password and you are in. You can now create databases and tables using a web user interface.
We need to do one more thing given that we have put our EC2 server up on the web as a web server which also has a database server. We need to security harden it. How to do this? Ubuntu makes it very easy for us.
sudo ufw enable
- This enables the Uncomplicated Firewall built-in to Ubuntu
sudo ufw allow 22
- This keeps the SSH port open
sudo ufw allow 80
- This keeps the Web Server Default port open
More on Uncomplicated Ubuntu Firewall here.
All this should take less than 4 mins if that. You have now been able to install the entire LAMP stack for yourself or your developer. With this you can get cranking on your next killer web application hosted on the reliable infrastructure of Amazon EC2.
Let me know if anyone has any other suggestions for this topic.

