Create an AWS Account
First things first: you need to create your AWS account. You can sign up here. You’ll have to provide a credit card and a phone number where you will be called as part of the online registration process for verification purposes. Amazon offers a Free Usage Tier, which is great to explore the services and even host real apps without being charged. Check the details here.
Create an Instance
Now that you have an AWS account, access the AWS Management Console and click the EC2 tab to create a new instance:
- Choose an AMI in the classic instance wizard: I chose the Basic 64-bit Amazon Linux AMI.
- Instance details: keep the default settings.
- Create a new key pair. Enter a name for your key pair (i.e. christophe) and download your key pair (i.e. christophe.pem).
- Select the quick start security group.
- Launch your instance.
SSH
Once your instance is running, you can ssh into it. First, you need to identify the address of your instance: Select the instance in the AWS Management Console, and look for the Public DNS in the instance description (bottom part of the screen).
Use that address (and a path to your .pem file) to ssh into your instance:
ssh ec2-user@ec2-50-17-14-16.compute-1.amazonaws.com -i ~/christophe.pem
Important Notes:
- You may have to chmod your .pem file as follows:
chmod 600 ~/christophe.pem - Depending on the image you chose, you may also have to replace ec2-user with root or ubuntu. ec2-user is what you need for an Amazon Linux AMI.
SFTP
At this point, you can also SFTP into your new instance using parameters similar to these:
host: ec2-50-17-14-16.compute-1.amazonaws.com
port: 22
user: ec2-user
password: Select your .pem file
Elastic IP
The public DNS address changes when you restart your instance. To get a permanent IP address, click Elastic IPs in the AWS Management Console (left navigation bar), allocate a new IP address and associate it with your instance.
Install Tomcat
To install tomcat, ssh into your instance and type the following command:
sudo yum install tomcat6 tomcat6-webapps
“tomcat6-webapps” is optional and will install the Tomcat sample apps. The configuration files are in /usr/share/tomcat6. To install your own web app, you can simply SFTP it to /usr/share/tomcat6/webapps.
To start Tomcat:
sudo service tomcat6 start
To stop Tomcat:
sudo service tomcat6 stop
The default Tomcat server uses port 8080. You need to open that port on your instance to make sure your Tomcat server is available on the Web (you could also change the default port). In the AWS Management Console, select Security Groups (left navigation bar), select the quick-start group, the Inbound tab and add port 8080. Make sure you click “Add Rule” and then “Apply Rule Changes”.
You should now be able to access your Tomcat server from a browser using (use your own Public DNS address or Elastic IP):
http://ec2-50-17-14-16.compute-1.amazonaws.com:8080/
MySQL
To install MySQL, ssh into your instance and type the following command:
sudo yum install mysql-server
To start MySQL:
sudo service mysqld start
To stop MySQL:
sudo service mysqld stop
MySQL Workbench
You can administer your database remotely using MySQL Workbench. You don’t have to open an additional port (i.e. 3306). Simply choose Standard TCP/IP over SSH in the Setup New Connection dialog as follows:



What is the AMI ID of the instance that you selected?
ami-1b814f72
Hi Christopher,
Just tried your employee details on flex mobile app. Just having some doubts in Manager and Direct Report parts. Can you please send me the clear code of that part??
Thanks for sharing such kind of wonderful information about java. Your blog is very informative. Please keep such beautiful postings.
As an FYI, I use FileZilla for sftp from my Windows 7 box. FileZilla uses a ppk file, not a pem file.
You can generate a ppk file from pem file from puttygen, which can be accessed here:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Run puttgen, load your pem file and then save the private key, which is a ppk file.
Within FileZilla, go to Edit->Settings…Connection->SFTP and add your private key/ppk file.
Now you can connect to your EC2 instance using SFTP, by just specifying the public dns or elastic IP address and the username ec2-user or root (depending on the AMI).
Hi,
I’m tring to use filezilla to transfer my app to tomcat6/webapps folder on the ec2 linux instance.
How did you get across the permission issue ” open for write: permission denied”
we login as ec2-user. in a putty session I can sudo. how do we do it using filezilla gui?
Thanks in advance.
Wonderfull
All these ideas will really help me in the future to have a successful blog MORE!!
Thanks a lot man!
Excellent help. My first attempt at doing anything with EC2 and it went through like a breeze.
Only step I got stuck. I’m using tomcat; mysql and I’m on windows 7 trying to open SSH using putty to the linux.
Downloaded putty; puttygen;
I had the *.pem file. which putty’s SSH>Auth did not accept.
Used puttygen to convert *.pem to *.ppk. I forget the blog entry that helped me. Else I would have quoted it here.
Everything else, including user id ec2-user…..was spot-on.
Thanks for sharing my man.
Kumar
so if i want to scale this setup … like say i want to have multiple tomcat or mysql..things like that..
how can we do it. I guess amazon cannot auto scale this setup on their own..
So are we left with creating another EC2 (or more ram on current one like more to micro to huge-ec2) and then
configure all our load balacing etc???
Thanks
Hari
Very well done article. It was a breeze.
I got a question. Under the Install tomcat section above you said open up the 8080 port that will allow to access http://ec2-50-17-14-16.compute-1.amazonaws.com:8080/. But lets say i use godaddy to setup domain, and then i want my website URL to point to this IP and port, on the godaddy DNS setup i am only able to specify IP. How do i make the URL go to this IP and then onto this specific port 8080?
Any luck on this? I’m also stuck with the same.
Guys, you need to follow your URL address with :8080, for example http://www.mygodaddydomainname.com:8080. No need to change the DNS name.
HTH
This was a fantastic tutorial. Clean, to the point, and easy to understand. Thanks!
EXCELLENT tutorial. This makes having a Java server on the internet amazingly easy.
Thank you very much… I was trying to connect by using ip address. Also i made many changes to config files so i didnt know where the prb is… Thank you for your information….
Great tutorial, thanks for taking the time to put up screenshots.
awesome, thanks
Thanks! Good explanation, to the point.
HI,
I had an ec2 instance running, I am using wamp server and running my php website.
Now I am implementing the searching functionality for that I want to install tomcat server..
Now my question is can I install tomcat server on the same instance with wamp server??
Thanks in Advance..
Praveen
Excellent points altogether, you simply received a new reader. What would you recommend about your submit that you just made some days in the past? Any certain?
Great post. Thanks for detailed information.
Excellent tutorial ! Thank you !