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:

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

  1. Lola LB November 16, 2011 at 5:28 pm #

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

  2. Christophe Coenraets November 16, 2011 at 6:08 pm #


    • Ravikiran December 30, 2014 at 1:31 pm #

      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.


  3. Dinesh Kumar November 21, 2011 at 9:41 am #

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

  4. hem chandra November 29, 2011 at 11:38 pm #

    Thanks for sharing such kind of wonderful information about java. Your blog is very informative. Please keep such beautiful postings.

  5. Alan Greenblatt December 1, 2011 at 3:34 pm #

    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 January 25, 2012 at 11:55 pm #

      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 December 23, 2015 at 2:28 am #

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

  6. carolo December 2, 2011 at 12:46 pm #


  7. TopHostingProviders December 5, 2011 at 8:56 am #

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

  8. Shu December 18, 2011 at 4:24 am #

    Thanks a lot man!

  9. Kumar January 20, 2012 at 1:57 am #

    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.

  10. Haribalan Raghupathy January 27, 2012 at 12:28 am #

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


  11. Zaid Ansari February 5, 2012 at 9:56 pm #

    Very well done article. It was a breeze.

  12. Abdus April 2, 2012 at 11:32 pm #

    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 July 6, 2012 at 8:12 am #

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

    • Netlander December 2, 2012 at 4:34 pm #

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

  13. WoolyNinja May 31, 2012 at 4:24 am #

    This was a fantastic tutorial. Clean, to the point, and easy to understand. Thanks!

  14. Girum Ibssa June 7, 2012 at 11:23 pm #

    EXCELLENT tutorial. This makes having a Java server on the internet amazingly easy.

  15. Nandish July 5, 2012 at 11:35 am #

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

  16. Gary July 9, 2012 at 8:38 pm #

    Great tutorial, thanks for taking the time to put up screenshots.

  17. slametz November 28, 2012 at 3:25 am #

    awesome, thanks

  18. Al Klein December 10, 2012 at 2:21 am #

    Thanks! Good explanation, to the point.

  19. Praveen January 31, 2013 at 2:58 pm #


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

  20. Интернет магазин March 18, 2013 at 9:31 pm #

    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?

  21. Satish April 13, 2013 at 10:01 am #

    Great post. Thanks for detailed information.

  22. Ovidiu May 5, 2013 at 7:33 am #

    Excellent tutorial ! Thank you !

  23. Ashutosh June 11, 2013 at 11:02 pm #

    simple, useful and informative, Thank You!!!

  24. Solens June 28, 2013 at 1:50 pm #

    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?

    • reshmi December 15, 2013 at 12:19 pm #

      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

  25. nginx tomcat July 15, 2013 at 9:25 am #

    Thanks for the tutorial. Easy to follow on using EC2

  26. adobe Photoshop cs6 book August 5, 2013 at 10:16 am #

    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.

  27. Shwetha August 6, 2013 at 6:14 pm #

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

  28. sreejith September 17, 2013 at 1:06 am #

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

  29. Anurag October 10, 2013 at 3:05 am #

    Thank you! :)

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

  31. Suresh November 7, 2013 at 12:37 am #

    Very nice article. Thank you so much.

  32. zolibra November 14, 2013 at 4:36 am #

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

  33. prakash November 20, 2013 at 1:31 am #

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

  34. Ramanan January 11, 2014 at 5:44 pm #

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

  35. Jesho February 7, 2014 at 10:07 am #

    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

  36. David April 9, 2014 at 9:57 am #

    Thanks a lot! was really useful ! :)

  37. Cindy Corritore April 13, 2014 at 12:31 pm #

    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?

  38. avast gratuit May 25, 2014 at 1:21 am #

    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!

  39. hypnosis anxiety June 14, 2014 at 12:27 am #

    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.

  40. cheap Nets 2014 jerseys June 15, 2014 at 12:01 pm #

    cheap china jerseys free shipping/cheap college jerseys from china

  41. cheap Wild jerseys from china June 16, 2014 at 6:24 am #

    Customized Senators new jerseys 2014

  42. network marketing tips July 14, 2014 at 5:00 am #

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

  43. pavankumar July 14, 2014 at 6:56 am #

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

  44. Daniel Nwankwo November 23, 2014 at 7:41 pm #

    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

  45. Kumaran February 11, 2015 at 3:46 pm #

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

  46. Arka Dutta March 28, 2015 at 7:34 am #

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

  47. sivarani April 3, 2015 at 10:33 pm #

    Thanks a lot

  48. ali khan April 4, 2015 at 12:32 am #

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

  49. ali khan April 10, 2015 at 1:09 am #

    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

  50. DGHGYDF YFDFD May 11, 2015 at 10:38 am #

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

  51. market raf August 25, 2015 at 9:36 am #

    good work and good shareds you are cool blogger

  52. market raf August 25, 2015 at 9:37 am #

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

  53. Sooraj August 26, 2015 at 2:00 am #


    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?

  54. futbol çorapları September 10, 2015 at 4:07 pm #

    Any chance you could make available a sample showing

  55. çelik raf September 13, 2015 at 4:46 pm #

    ben cok begendım her zaman girip okuyorum

  56. forma imalatı November 16, 2015 at 4:03 am #

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

  57. futbol çorapları November 19, 2015 at 9:53 am #

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

  58. backlink ekle February 4, 2016 at 3:57 pm #

    harika bir sayfa bekleriz

  59. Sam February 27, 2016 at 1:21 am #

    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 February 27, 2016 at 1:22 am #
    • Shubham Aggarwal August 19, 2016 at 11:59 am #

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

  60. aws training June 9, 2016 at 8:47 am #

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

  61. Gilad Somjen September 9, 2016 at 12:26 pm #

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

  62. Eoghan Hynes September 21, 2016 at 12:26 pm #

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

  63. anil November 9, 2016 at 6:53 am #

    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

  64. AWS training in hyderabad April 15, 2017 at 5:24 am #

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

  65. aptron11 October 3, 2018 at 3:42 am #

    Thanks for sharing the great post.
    AWS Training

  66. Online iPhone Cases November 13, 2018 at 7:24 am #

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

  67. Tiago R. January 31, 2019 at 5:36 am #

    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.

  68. Rhianne Jane August 18, 2019 at 11:57 pm #

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

  69. gautham cynixit December 7, 2019 at 1:51 am #

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

  70. Akhilesh Singh March 10, 2020 at 2:47 am #

    nicely written.
    AWS as a career is new trend.

    I have done AWS with NG Networks:

  71. Jeyanthi R July 4, 2020 at 3:55 am #

    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.

  72. yuvaraj singh December 9, 2020 at 2:39 am #

    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

  73. anuj.asinfo March 18, 2021 at 6:47 am #

    Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot.
    Thanks for sharing.
    Digital Marketing course in Gurgaon


  1. Links for November 14th through November 15th — Vinny Carpenter's blog - November 15, 2011

    […] Set Up an Amazon EC2 Instance with Tomcat and MySQL – 5 Minutes Tutorial – Set Up an Amazon EC2 Instance with Tomcat and MySQL – 5 Minutes Tutorial […]

  2. – Amazon Kindle Books – 6 Settings Amazon Sites – (3/02/2012) | Amazon Fire Tablet - February 3, 2012

    […] Set Up an Amazon EC2 Instance with Tomcat and MySQL 5 .Nov 15, 2011 Create an AWS Account. First things first: you need to create your AWS account. You can sign up here. […]

  3. Installing mySQL on AWS EC2 Ubuntu Machine through SSH « Application & Program Tips « Electronic Services - May 10, 2012

    […] Also, a really good, AWS EC2 direct tutorial for setting up mySQL on the server can be found at Christophe Coenraets site. […]

  4. Creating an Amazon EC2 Instance « SoftwareSanders - August 21, 2012

    […]… Share this:TwitterFacebookLike this:LikeBe the first to like this. […]

  5. Set Up an Amazon EC2 Instance with Tomcat and MySQL – 5 Minute Tutorial | TechnoVeille - September 3, 2012

    […] original : ici ‹ Tutorial: HTML Templates with Mustache.js Tagués avec : Amazon EC2, […]

  6. Tomcat etc | Firelife - February 25, 2013

    […]… […]

  7. Erro Datasource Tomcat na Amazon EC2 (Linux) | Aristides Neto Blog - June 6, 2013

    […] Existem vários tutoriais que ajudam nesse processo de configuração, como esse aqui. […]

  8. Grails on AWS | Greg Stephens Blog - July 23, 2013

    […] addition to Bobby Warner’s post I found the post by Christophe Coenraets on EC2 with Tomcat & MySQL and Liferay on Amazon […]

  9. Set Up an Amazon EC2 Instance with Tomcat and MySQL – 5 Minute Tutorial | indybee83 - December 30, 2013

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

  10. Set Up an Amazon EC2 Instance with Wildfly, MySQL, Git, Jenkins | Nuwan Blog - April 23, 2015

    […] Reference:… […]

  11. awsのtomcat8でjenkinsを動かす環境構築 | エンジニアの夢は終わらねェ - June 29, 2015

    […] Set up Amazon ec2 instance with tomcat and mysql […]

  12. Amazon Ami Tomcat | Smiling Experts - July 26, 2015

    […] Set Up an Amazon EC2 Instance with Tomcat and MySQL – … – 66 Responses to Set Up an Amazon EC2 Instance with Tomcat and MySQL – 5 Minute Tutorial […]

  13. Godaddy Port Number Filezilla - November 18, 2015

    […] Set Up an Amazon EC2 Instance with Tomcat and MySQL … – 72 Responses to Set Up an Amazon EC2 Instance with Tomcat and MySQL – 5 Minute Tutorial […]

  14. Creating Elastic IPs to sort of maintain static DNS – Mantura - October 22, 2016

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

Leave a Reply