Day 13 of 90 Days Of DevOps Challenge: Deploy Web Application Using Apache Tomcat


Yesterday, I explored Maven, a powerful build and deployment tool for standalone Java projects. Today, I continued my DevOps journey by learning how to set up and use the Tomcat server to deploy Java web applications. Here's everything I learned, step-by-step!
What is Web Server?
A server is a software system designed to run and manage web applications. It plays a crucial role in the client-server architecture by handling requests from clients (users) and delivering appropriate responses.
How Does It Work?
Users access a web application by sending HTTP requests to the server using a client software, such as a web browser. The server receives these requests, processes them, and returns the requested resources or data.
Responsibilities of a Web Server:
Accept and interpret client requests.
Process application logic (if applicable).
Return the appropriate responses
Popular Web Servers in the Market
There are several well-known servers used to host and run web applications, including:
Apache Tomcat – Lightweight Java-based web server
JBoss – Java EE application server from Red Hat
GlassFish – Open-source Java EE server
WebLogic – Enterprise-level server by Oracle
WebSphere – IBM’s application server
IIS (Internet Information Services) – Microsoft’s web server for Windows environments
Understanding Build and Deployment
In the software development lifecycle, the process of making an application ready for execution involves two critical phases:
Build
This phase includes compiling the source code, running tests, and packaging the application (e.g., generating a.jar
or.war
file).Build = Compile + Test + Package
Deployment
Deployment refers to the process of executing and running the built application on a server so that users can access it.Deployment = Execution
Apache Tomcat Server
Apache Tomcat is a lightweight, open-source web server and servlet container developed by the Apache Software Foundation. It's primarily used to deploy and run Java-based web applications.
Key Highlights:
Free & open source, built using Java.
Requires Java to be installed for execution.
Cross-platform support (Linux, Windows, macOS).
Default port: 8080 (configurable).
Supports Servlets, JSP, and WebSocket technologies.
NOTE: Java must be installed before running Tomcat.
Setting Up Tomcat Server on Linux (AWS)
Step 1: Create and Connect to a Linux VM
Create a EC2 instance on AWS.
Connect using tools like MobaXterm, PuTTY, or Git Bash.
Step 2: Install Maven (Java is included)
sudo yum install maven
NOTE: Maven not only helps in building Java projects, but it also installs Java dependencies when set up.
Step 3: Download Tomcat
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.89/bin/apache-tomcat-9.0.89.tar.gz
Step 4: Extract the tar File
tar -xvf apache-tomcat-9.0.89.tar.gz # Extract tar file
cd apache-tomcat-9.0.89 # Go to apache tomcat folder
ls -l # Check the extracted files inside folder
Tomcat Directory Structure
Understanding Tomcat’s directory structure is essential for effectively deploying and managing Java web applications. Here's a breakdown of the key folders:
bin/
– Startup & Shutdown Scripts
This folder contains scripts to start and stop the Tomcat server.
Windows:
startup.bat
,shutdown.bat
Linux/macOS:
startup.sh
,shutdown.sh
conf/
– Configuration Files
Houses all the configuration files needed to run and secure your server.
server.xml
: Main server configurationtomcat-users.xml
: User roles and credentials
webapps/
– Deployment Folder
This is the default folder where you deploy applications. Simply placing a .war
file here will trigger automatic deployment by Tomcat.
logs/
– Log Files
Stores server logs such as access logs, error logs, and startup logs. These are invaluable for troubleshooting and monitoring server activity.
lib/
– Java Libraries
Contains all the necessary .jar
files that Tomcat requires to function properly. You can also add custom libraries here if needed by your web app.
temp/
– Temporary Files
Used by Tomcat to store temporary data during runtime.
Safe to delete if needed; Tomcat recreates it as necessary.
Key Tomcat Files and Commands
To work efficiently with Apache Tomcat, it’s important to get familiar with a few essential files and scripts. These help in starting/stopping the server, configuring it, and deploying applications.
File/Script | Usage |
startup.sh | Starts the Tomcat server (Linux/macOS) |
shutdown.sh | Stops the Tomcat server (Linux/macOS) |
server.xml | Main server configuration file |
tomcat-users.xml | Contains user credentials and role configurations |
.war file in webapps/ | Deploys a web application automatically |
NOTE: If you're on Windows, use startup.bat
and shutdown.bat
instead of .sh
scripts.
Deploying a Java Web Application on Tomcat
Build your application using Maven or your IDE.
Package the app into a
.war
file.Move the WAR file into the
webapps/
directory.Start the server using:
./bin/startup.sh
Access the application at:
http://<ec2-ip>:8080/<WebAppName>
Final thoughts
Today’s learning experience with Tomcat was both insightful and practical. Building on yesterday’s exploration of Maven, I understood how web applications are deployed and managed on a server. Setting up Tomcat on a Linux VM and working through its directory structure gave me a deeper appreciation for the deployment process. Seeing a .war
file come to life in the browser was incredibly satisfying. Overall, it was a valuable step forward in my DevOps journey.
Subscribe to my newsletter
Read articles from Vaishnavi D directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
