Sitemap
D-Adda

D-Adda

DevOps Engineer

Tomcat

6 min readDec 2, 2024

--

Apache Tomcat

Before starting Apache Tomcat, we should know about the following key aspects:

What is server?

A server is a computer or system that provides resources, services, or functionality to other computers or devices, known as clients, over a network. It is designed to respond to client requests and fulfil specific roles or functions. Servers can exist in various forms, including hardware servers and software-based servers. There are a wide range of servers like Web Server, Mail Server, Database Server, File Server and so on.
Servers usually have more power, memory, and storage than regular computers and are built to handle many requests at once. Managing servers can be complex, so many businesses hire server management companies to ensure their servers run smoothly, securely, and efficiently.

What is a Web Server?

Web server is a software or hardware system that hosts websites, stores their resources (e.g., HTML files, images, CSS), and delivers the content over the internet (or intranet) to clients, such as web browsers, by processing HTTP or HTTPS requests. Web servers are the backbone of the full-stack project, ensuring seamless communication between frontend (what users see) and backend (the server-side processes and databases).

Key Features of a Web Server:

  • HTTP Protocol: Web servers use the HTTP (Hypertext Transfer Protocol) to communicate with clients.
  • Serving Static and Dynamic Content: They can serve both static content (like images and text) and dynamic content (like user-generated data).
  • Hosting Websites: Web servers host websites and web applications.
  • Security: Web servers also manage security features like SSL/TLS for secure connections (HTTPS).

Types of Web Servers and Their Examples

Web servers can be classified into different types based on factors like the operating system they run on, the programming language they support, and the type of content they serve. Here’s a breakdown of these classifications with examples:

1️⃣ Operating System-based Web Servers:

1.Linux Web Servers: These web servers are typically optimized to run on Linux-based systems.
Examples:

  • Apache: A highly flexible and popular web server used for both static and dynamic content.
  • Nginx: Known for its high performance, particularly for handling static content and acting as a reverse proxy.
  • Lighttpd: A lightweight web server known for its low memory footprint and high performance, often used for serving static content.

2. Windows Web Servers: These web servers are designed to run on Windows operating systems.
Examples:

  • Internet Information Services (IIS): A web server developed by Microsoft, often used in Windows-based environments.
  • Apache: Available for Windows, Apache can also run on this platform, though it is more commonly used on Linux.
  • Nginx: While primarily used on Linux, Nginx also runs on Windows and can be used for reverse proxying and serving content.

2️⃣Programming Language-based Web Servers:

1.PHP Web Servers: These servers are designed to work well with PHP, a popular programming language for web development.
Examples:

  • Apache with mod_php: A module for Apache that allows it to process PHP scripts.
  • Nginx with PHP-FPM: Nginx paired with PHP-FPM (FastCGI Process Manager) is commonly used for high-performance PHP hosting.
  • Lighttpd with FastCGI: Lighttpd can be configured to use FastCGI to serve PHP applications.

2. Python Web Servers: These servers are optimized for running Python-based web applications.
Examples:

  • Gunicorn: A popular WSGI (Web Server Gateway Interface) HTTP server for Python web applications.
  • uWSGI: A versatile application server that supports WSGI and is commonly used with Python web frameworks like Django and Flask.
  • mod_wsgi: An Apache module for serving Python web applications, often used in conjunction with the Apache server.

3. Ruby Web Servers: These web servers are tailored for Ruby applications.
Examples:

  • Puma: A fast and concurrent HTTP server for Ruby web applications, commonly used with Rails.
  • Unicorn: A Rack-compatible HTTP server designed for Ruby applications, focusing on performance and handling multiple requests.
  • Passenger: A web server and application server for Ruby, optimized for ease of use and deployment with Ruby on Rails.

4. Java Web Servers: These web servers are used for serving Java-based applications.
Examples:

  • Apache Tomcat: A widely used Java-based web server and servlet container for running Java applications.
  • Jetty: A lightweight and flexible Java-based server, often used in embedded systems and for serving REST APIs.
  • GlassFish: A Java EE (Enterprise Edition) application server that supports full-stack Java applications.

3️⃣Application Type-based Web Servers:

1.Static-content Web Servers: These servers are optimized for serving static files, such as HTML, CSS, JavaScript, and images.
Examples:

    Get D-Adda’s stories in your inbox

    Join Medium for free to get updates from this writer.

  • Nginx: A highly efficient server for serving static content, often used as a reverse proxy.
  • Apache: Can serve both static and dynamic content, but is also widely used for static content hosting.
  • Caddy: A modern web server that comes with automatic HTTPS and is designed for simplicity, often used for serving static sites.

2. Dynamic-content Web Servers: These servers are designed to process and serve dynamic content, often interacting with databases and server-side scripts.
Examples:

  • Apache Tomcat: A Java-based server that serves dynamic content, often used for Java web applications.
  • Node.js: A server-side JavaScript environment that can handle dynamic content, often used with web frameworks like Express.
  • Ruby on Rails (via Puma, Unicorn, or Passenger): A web server environment for running Ruby on Rails applications, which are dynamic in nature and interact with databases.
apache tomcat

Apache Tomcat is popular open-source web server and servlet container developed by the Apache Software Foundation that is used to run Java-based web applications. It is primarily used to serve Java-based web applications, specifically those using Java Servlets and JavaServer Pages (JSP). Tomcat provides a platform for running Java web applications by implementing the Java EE (Enterprise Edition) specifications for web containers.

Core Components of Tomcat

  • Catalina: Core servlet container that processes HTTP requests and responses.
  • Coyote: HTTP connector that processes HTTP requests and sends them to Catalina.
  • Jasper: JSP engine that compiles and processes JavaServer Pages (JSP).
  • Cluster: Provides clustering for multiple Tomcat instances to work together.
  • Host: Represents a virtual host (a domain) in Tomcat for serving web apps.
  • Engine: Routes requests to the correct virtual host or application.
  • Connector: Handles communication between clients and Tomcat (HTTP, AJP, etc.).
  • Realm: Manages user authentication and authorization for web applications.
  • Context: Represents a single web application and its configuration.
  • Manager: Manages deployment, redeployment, and lifecycle of web applications.
  • Valve: Adds additional functionality like security, logging, etc.
  • Lifecycle Listener: Monitors lifecycle events of Tomcat components and executes actions.

Root of your Tomcat:
/home/tomcat/apache-tomcat-9.0.10

Features of Apache Tomcat

  • Open Source: Free and open-source software, maintained by the Apache Software Foundation.
  • Servlet and JSP Support: Implements Java Servlet and JavaServer Pages (JSP) specifications for dynamic content.
  • Cross-platform: Works on various operating systems like Windows, Linux, and macOS.
  • Lightweight: A small, efficient footprint, ideal for lightweight web applications.
  • High Performance: Optimized for handling a large number of concurrent requests efficiently.
  • Web Application Deployment: Supports the deployment of Java web applications packaged as WAR (Web Application Archive) files.
  • Security Features: Includes built-in security features like authentication, authorization, and SSL/TLS support.
  • Clustering and Load Balancing: Supports clustering for high availability and load balancing across multiple servers.
  • Extensibility: Allows customization through various components like Valves, Listeners and Filters.
  • Management Interface: Provides a web-based manager for deploying, monitoring and managing applications.

Example Use Case

A typical use case for Tomcat is deploying a Java-based web application, such as an e-commerce site or a content management system, that uses servlets and JSPs for dynamic content generation. Tomcat would handle incoming HTTP requests, route them to the appropriate servlets or JSPs, and generate the appropriate responses to be sent back to the client.

Apache Tomcat is an open-source web server and servlet container developed by the Apache Software Foundation. It is designed to execute Java Servlets and render web pages that use Java Server Pages (JSP). Tomcat is often used to host Java-based web applications and is known for its performance, reliability, and scalability.

Overall, Apache Tomcat is a popular choice for developers who need a robust and lightweight environment to run Java-based web applications.

Installing and Configuring Apache Tomcat on Linux

Prerequisites:

  • EC2 instance running Amazon Linux 2.
  • Java Development Kit (JDK) installed on the system (required to run Apache Tomcat).
Step-1: Update the System Packages
sudo yum update -y

Step-2: Install Java (JDK) (OpenJDK 8 or OpenJDK 11)
sudo yum install java-1.8.0-openjdk -y

java -version # check java version

Step-3: Download Apache Tomcat
# Go https://tomcat.apache.org/download-90.cgi on this official website
→ Download→Tomcat 9 → Core: → zip (pgp, sha512) copy this link
cd /opt
wget <paste copied link>
ls
unzip <apache-tomcat-9.0.93>
mv apache-tomcat-9.0.93/ tomcat9 #rename this file

Step-4: Access Apache Tomcat Web Interface
http://<your-ec2-public-ip>:8080

--

--