Getting Started with Tomcat on AWS EC2 (Amazon Linux)

If you're deploying Java web applications on a Linux VM in the cloud, Apache Tomcat is a top choice. In this guide, you'll learn what a server is, how Tomcat works, and how to set it up on an Amazon Linux EC2 instance. By the end, you'll be able to deploy your own WAR files and even access the Tomcat Admin Console remotely.


🌐 What is a Server?

A server is software designed to handle requests from users and serve responses, usually over the internet. Think of it as the engine behind every web application.

  • Clients (like your browser) send requests to servers.

  • Servers process these requests and send back responses.

  • Popular web servers include:

    • Apache Tomcat

    • JBoss

    • WebLogic

    • WebSphere

    • IIS

✅ Note: A web server is essential for deploying and running web applications.


🐱 What is Tomcat?

Apache Tomcat is:

  • Free and open-source

  • Developed by the Apache Software Foundation

  • Written in Java

  • Runs Java-based web applications (Servlets, JSP)

  • Default port: 8080

  • Cross-platform

📌 To run Tomcat, ensure Java is installed on your system.


☁️ Setting Up Tomcat on AWS EC2 (Amazon Linux)

Step 1: Launch an EC2 Instance

  • Use Amazon Linux AMI

  • Connect using MobaXterm, PuTTY, or Git Bash

Step 2: Install Maven (which installs Java too)

bashCopyEditsudo yum install maven

Step 3: Download Tomcat

bashCopyEditwget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.89/bin/apache-tomcat-9.0.89.tar.gz

Step 4: Extract Tomcat

bashCopyEdittar -xvf apache-tomcat-9.0.89.tar.gz
cd apache-tomcat-9.0.89
ls -l

🗂 Tomcat Directory Structure

FolderDescription
binStartup & shutdown scripts
confConfiguration files like server.xml, tomcat-users.xml
webappsDeployment folder (place your .war files here)
logsStores server logs
libContains required JARs
tempTemporary working files

🚀 Deploying a Web App on Tomcat

  1. Create a Maven Web App:
bashCopyEditmvn archetype:generate -DgroupId=in.ashokit -DartifactId=my-web-app -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeVersion=1.4 -DinteractiveMode=false
  1. Package the app:
bashCopyEditcd my-web-app
mvn clean package
  1. Deploy the WAR file:
bashCopyEditcp target/my-web-app.war /path-to-tomcat/webapps/
  1. Start the Tomcat server:
bashCopyEditcd /path-to-tomcat/bin
sh startup.sh
  1. Add port 8080 to Security Group > Inbound Rules in AWS.

  2. Access your app:

perlCopyEdithttp://<ec2-public-ip>:8080/my-web-app

🔐 Enable Tomcat Admin Console Remotely

  1. Modify access control in:
bashCopyEdittomcat/webapps/manager/META-INF/context.xml

Change:

xmlCopyEdit<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow=".*" />
  1. Add users in tomcat/conf/tomcat-users.xml:
xmlCopyEdit<role rolename="manager-gui" />
<role rolename="manager-script" />
<role rolename="admin-gui" />

<user username="tomcat" password="tomcat" roles="manager-gui" />
<user username="admin" password="admin" roles="manager-gui,admin-gui,manager-script"/>
  1. Restart Tomcat and access:
cppCopyEdithttp://<ec2-public-ip>:8080/

🛠 Use Manager App to deploy/undeploy apps via browser.


🔁 Change Tomcat Port Number

  • Edit server.xml in:
pgsqlCopyEdittomcat/conf/server.xml

Change:

xmlCopyEdit<Connector port="8080" ... />

to any available port, like 9090.

  • Restart Tomcat.

  • Add the new port to your EC2 Security Group inbound rules.

  • Access:

cppCopyEdithttp://<ec2-public-ip>:9090/

📝 Summary

Here's what you learned today:

✅ What a server is
✅ What Tomcat does
✅ How to set up Tomcat on AWS EC2
✅ WAR file deployment
✅ Tomcat admin console access
✅ Changing default port


📌 Tomcat is a lightweight, powerful choice for hosting Java-based web applications—perfect for cloud environments like AWS EC2.

10
Subscribe to my newsletter

Read articles from Prashant Mahamuni directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prashant Mahamuni
Prashant Mahamuni