This is a beginner’s guide to setting up an AWS EC2 instance with Ubuntu/Tomcat7/MySQL.
- Create AWS account: Creant an AWS account with your personal and credit card details and login to AWS console. If you are an existing Amazon cusotmer, you can login with that account. AWS provides a free tier which is worth exploring. I have deployed two websites on free tier instances that are functioning smoothly.
- Configure Security Group: Next you need to set up a security group to which the instance will belong. A security group is where you enable the ports you want your instance to listen on. A default security group already exists which you can modify. Click on Network & Security options in the left pane and edit the default security group to add http, https and ssh ports to the Inbound tab. Without this, your instance won’t respond to any incoming http, https and ssh requests. Other data transfer protocols need to be added here if required.
- Create Instance: To launch an AWS instance, select Instances from the left pane and click on launch instance. Give your instance a descriptive name. Create a new public/private key pair and download the key which is a .pem file needed to connect to your server. Store this file in a secure location. Select the configuration for your server and make sure you select the default security group you just edited in the previous step. Security group needs to be configured before launching the instance because you won’t be able to change it afterwards. Once your instance launches, you can see its details by clicking on Instances option from the left pane in the console.
- SSH Into The Instance: Launch Command Prompt and cd to the directory where your .pem file is stored.
ssh -i keyname.pem ubuntu@publicIP
You can get the public IP of your instance from AWS Console > Instances. You may need to modify permissions of the .pem file if required
chmod 600 keyname.pem
- Installations: After sshing into the instance, update Ubuntu package manager and installed packages
sudo apt-get update sudo apt-get dist-upgrade
sudo apt-get install mysql-server
sudo apt-get install tomcat7 tomcat7-webapps
- Running Tomcat on Port 80: By default tomcat listens for http requests on port 8080 but by default browser http requests are sent to port 80. In order to fulfill them, you need to configure tomcat to run on port 80. First you need to modify the HTTP connector in conf/server.xml
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
Then you need to follow a few more steps mentioned here.