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

Vaishnavi DVaishnavi D
4 min read

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

There are several well-known servers used to host and run web applications, including:

  1. Apache Tomcat – Lightweight Java-based web server

  2. JBoss – Java EE application server from Red Hat

  3. GlassFish – Open-source Java EE server

  4. WebLogic – Enterprise-level server by Oracle

  5. WebSphere – IBM’s application server

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

  1. bin/Startup & Shutdown Scripts

This folder contains scripts to start and stop the Tomcat server.

  1. conf/ – Configuration Files

Houses all the configuration files needed to run and secure your server.

  • server.xml: Main server configuration

  • tomcat-users.xml: User roles and credentials

  1. webapps/Deployment Folder

This is the default folder where you deploy applications. Simply placing a .war file here will trigger automatic deployment by Tomcat.

  1. logs/Log Files

Stores server logs such as access logs, error logs, and startup logs. These are invaluable for troubleshooting and monitoring server activity.

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

  1. 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/ScriptUsage
startup.shStarts the Tomcat server (Linux/macOS)
shutdown.shStops the Tomcat server (Linux/macOS)
server.xmlMain server configuration file
tomcat-users.xmlContains 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

  1. Build your application using Maven or your IDE.

  2. Package the app into a .war file.

  3. Move the WAR file into the webapps/ directory.

  4. Start the server using:

     ./bin/startup.sh
    
  5. 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.

0
Subscribe to my newsletter

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

Written by

Vaishnavi D
Vaishnavi D