Set Up an Amazon EC2 Instance with Tomcat and MySQL – 5 Minute Tutorial

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.


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 -i ~/christophe.pem

Important Notes:

  1. You may have to chmod your .pem file as follows:
    chmod 600 ~/christophe.pem
  2. 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.


At this point, you can also SFTP into your new instance using parameters similar to these:

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


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:

  • Pingback: Links for November 14th through November 15th — Vinny Carpenter's blog()

  • Lola LB

    What is the AMI ID of the instance that you selected?

  • Christophe Coenraets


    • Ravikiran

      Hi Christopher,

      I am using AWS Linux instance (RHEL 7) to host my application. But have few issues

      1. Not able get the GUI mode. If options is available then how?
      2. I have installed JAVA, Tomcat successfully through commands and want to install MySQL through command too but could not install. The error command says /usr/bin/per module is not available.

      Please suggest and advice me how to do it.

      I have gone though above post by entering SQL command from root (sudo yum install mysql-server) but it says (Could not contact CDS load balancer, trying others.

      Could not contact any CDS load balancers:,

      Please suggest as my installations are struck badly.


  • Dinesh Kumar

    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.

  • Alan Greenblatt

    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:

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

    • KUmar

      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.

      • kaushal

        just change the ownership of file to ec2-user you will be able to do that

  • carolo


  • All these ideas will really help me in the future to have a successful blog MORE!!

  • Shu

    Thanks a lot man!

  • Kumar

    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.

  • Haribalan Raghupathy

    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???


  • Pingback: – Amazon Kindle Books – 6 Settings Amazon Sites – (3/02/2012) | Amazon Fire Tablet()

  • Zaid Ansari

    Very well done article. It was a breeze.

  • Abdus

    I got a question. Under the Install tomcat section above you said open up the 8080 port that will allow to access 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?

    • Saket

      Any luck on this? I’m also stuck with the same.

    • Netlander

      Guys, you need to follow your URL address with :8080, for example No need to change the DNS name.

  • Pingback: Installing mySQL on AWS EC2 Ubuntu Machine through SSH « Application & Program Tips « Electronic Services()

  • WoolyNinja

    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.

  • Nandish

    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.

  • Pingback: Creating an Amazon EC2 Instance « SoftwareSanders()

  • Pingback: Set Up an Amazon EC2 Instance with Tomcat and MySQL – 5 Minute Tutorial | TechnoVeille()

  • slametz

    awesome, thanks

  • Al Klein

    Thanks! Good explanation, to the point.

  • Praveen


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

  • Pingback: Tomcat etc | Firelife()

  • 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?

  • Satish

    Great post. Thanks for detailed information.

  • Ovidiu

    Excellent tutorial ! Thank you !

  • Pingback: Erro Datasource Tomcat na Amazon EC2 (Linux) | Aristides Neto Blog()

  • Ashutosh

    simple, useful and informative, Thank You!!!

  • Solens

    Great tutorial! It works smoothly for port 8080, however, I need to setup several instances of tomcat from 8080 to 8088, how can I open the remaining ports on EC2?

    • hi i have install tomcat but when
      i give the url in browser its not working even the port is changes and
      apply rules has been done. Please respond

  • Thanks for the tutorial. Easy to follow on using EC2

  • Pingback: Grails on AWS | Greg Stephens Blog()

  • Folks can also check out Inkscape ( which can be a extremely great program for
    vector graphics similar to AI. It is going to import AI files and
    can create SVG files which are compatible with AI.

  • Shwetha

    Very informative article.. Setup my Amazon instance in quite literally 5 min.. Thanks Christophe

  • sreejith

    It shows internal server error while accessing the JSP after installing Tomcat. Is that related with Java Hosting apps permissions or tomcat instance?

  • Anurag

    Thank you! :)

  • Often, you will give your body approximately 500
    more calories per gram, while fat contains 9 calories per gram
    than either carbohydrates or protein. Stay away from weight gain powders.

    If helps the internal systems and promote the healthy functioning
    of different parts of the body in balance.
    Combined with weight training exercise will put the
    muscles under stress and force them to grow. This is one
    of the three mass gainer major energy sources.

  • Suresh

    Very nice article. Thank you so much.

  • zolibra

    the free tier only have 600M memory , which has no chance to load a big WAR..that’s the problem

  • prakash

    Such an awesome tutorial. You almost saved my day. Thank you

  • Pingback: Set Up an Amazon EC2 Instance with Tomcat and MySQL – 5 Minute Tutorial | indybee83()

  • Ramanan

    Clean and well written article. Good work Chris !!!

  • Jesho

    Awesome article. Had a prob with the putty username and finally realized it as ‘ec2-user’. Other than that everything specified in the article was awesome

  • Thanks a lot! was really useful ! :)

  • Cindy Corritore

    Great great information. I have one issue – I am trying to connect to my LAMP instance on AWS using mySQL Workbench. Your screenshot (last image in your post) was perfect, except that mine won’t connect – it says “Could not connect the SSH tunnel Authentication Error’. I am using ec2-user for the user name, no pw, and my .pem file (created on AWS). Thoughts?

  • Hey would you mind stating which blog platform you’re using?
    I’m planning to start my own blog in the near future but I’m having a difficult time selecting between BlogEngine/Wordpress/B2evolution and
    Drupal. The reason I ask is because your design and style seems
    different then most blogs and I’m looking for something unique.
    P.S My apologies for being off-topic but I had to ask!

  • Many people have quickly been able to dramatically improve their lives through the power of hypnosis.
    These ways on inducing hypnosis are taught by Ledochowski through his very
    own covert hypnosis course. any person who has ever dieted and failed knows the biggest obstacles to weight
    loss can be in the mind.

  • cheap china jerseys free shipping/cheap college jerseys from china

  • Customized Senators new jerseys 2014

  • I visit everyday a few sites and sites to read content, however this website presents quality based articles.

  • pavankumar

    Fant Blog man!! Helped a lot..Keep writing..:)

  • Thank you for the blog, it will help me and I have been looking for something like this. One question please, if I stop the instance what happens to the data in the database, is it lost, is it only held in memory? Same question for the tomcat webapp files.
    Thank you

  • Kumaran

    Great tutorial, quick and to the point,
    thank you very much

  • Arka Dutta

    For the mysql installed , what is the password for root user.

  • sivarani

    Thanks a lot

  • ali khan

    Therefore, you must look for for quality SEO solutions to accomplish your focus on clients quickly and basically. binární opce

  • ali khan

    Marketing your organization through SEO is a fantastic decision as with today’s demands within the organization industry, you need to come up with the best possible method to get ahead of your competitors. brokeři na binární opce

  • Pingback: Set Up an Amazon EC2 Instance with Wildfly, MySQL, Git, Jenkins | Nuwan Blog()


    That’s already the responsibility of a lawyer. They should working as a professional for their client, whoever they was. Interest Rate Policy

  • Pingback: awsのtomcat8でjenkinsを動かす環境構築 | エンジニアの夢は終わらねェ()

  • Pingback: Amazon Ami Tomcat | Smiling Experts()

  • good work and good shareds you are cool blogger

  • çok fazla haber ve paylaşımlar var helal olsun

  • Sooraj


    I did all the think that you have mention but I ran into an issue. Tomcat opened in my local browser on 8080 port but I cannot access any of the other pages. Like manager, tutorial, etc. all those pages give me a 404 not found page.

    Can you help me on this?

  • Any chance you could make available a sample showing

  • ben cok begendım her zaman girip okuyorum

  • herşey kaliteli üretim.Все качества продукции.Everything quality production

  • Pingback: Godaddy Port Number Filezilla()

  • His highest production of our company, we use the sport socks products: cotton, cotton, polyester, nylon and lycra. It includes anti-bacterial.

  • harika bir sayfa bekleriz

  • Sam

    I tried to start tomcat in port 80. But it gave me below error.

    SEVERE: Error starting endpoint Permission denied :80

    I configured server.xml as follows.

    Can some one help me to resolve this issue?

    • Sam
    • Did you create an Inbound connect for port 80? Tried using sudo?

  • I have got an great information on amazon ec2…Thanks for posting boss..

  • Gilad Somjen

    Or you can just use – Install AWS servers in just mins… FREE.

  • Eoghan Hynes

    Can you run your wine cellar project as it is with this configuration, ie; on tomcat with MySQL in AWS.

  • Pingback: Creating Elastic IPs to sort of maintain static DNS – Mantura()

  • anil

    how can i run multiple java project on single instance.
    Like : i have a parent domain: i want to create subdomains :, test1,abc,com

    i mean where i have to put the project war files.

    please help

  • AWS training in hyderabad

    Hello Coenraets,
    Thanks for this great info. very well explained via images.

  • Thanks for sharing the great post.
    AWS Training

  • Your blog is very interesting. Thanks for Sharing.
    iPhone Cases and Covers

  • Tiago R.

    Please, I have a doubt. If I configure only one EC2 instance with a tomcat server, for example. Is it able to scale up or I have to create a cluster of tomcat a configure everything by myself ? Thank you.

  • Rhianne Jane

    Good post. I learn something new and challenging on websites I stumble upon on a daily basis.

  • gautham cynixit

    In business intelligence there are various technologies available learn on msbi through msbi online training india

  • nicely written.
    AWS as a career is new trend.

    I have done AWS with NG Networks:

  • Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

  • yuvaraj singh

    Thanks for sharing this informative content , Great work
    Leanpitch provides online training in Product Management Launchpad during this lockdown period everyone can use it wisely.
    Product Management Workshop