Install and Configure Apache Tomcat 10 on Ubuntu 24.04 LTS (Step-by-Step Guide)

Introduction

Apache Tomcat is an open-source Servlet Container that runs Java applications. It supports the Java Servlet, JavaServer Pages (JSP), and WebSocket technologies, making it suitable for deploying dynamic web applications. Tomcat is an open source Java Servlet container lightweight, flexible and Most Popular in the world for hosting java-based web service and Enterprise Applications.. 

Prerequisites

  • 1 Core CPU and 1 GB Memory 
  • 2 GB disk space (This will be a minimal requirement, Click here for offical website.)

In this post, We are going to show you how to install Apache Tomcat 10 on Ubuntu 24.04 LTS.

Step 1: Run System Update & Upgrade 

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

sudo apt-get update && sudo apt-get upgrade -y


Step 2: Installing JAVA 11  

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

sudo apt-get install openjdk-11-jdk -y

To verify installed JAVA version. 

java -version


Step 3: Crearting Tomcat User and Group   

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

To add the group.

sudo groupadd tomcat

To add the system user.

sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat



Step 4: Downloading Apache Tomcat 10  

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

To change diretory

cd /tmp

To install curl utility if needed.

sudo apt-get install curl -y

To download the apache tomcat 10, Click here to download latest version of tomcat.

curl -O curl -O https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.34/bin/apache-tomcat-10.1.34.tar.gz



Step 5: Extrating Apacha Tomcat 10  

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

To make tomcat directory.

sudo mkdir /opt/tomcat

To extract the tar file of apache tomcat.

sudo tar xzvf apache-tomcat-10*tar.gz -C /opt/tomcat --strip-components=1

To change directory.

cd /opt/tomcat

To updating the groups.

sudo chgrp -R tomcat /opt/tomcat

To updating the permission.

sudo chmod g+x conf

To make chnage and modification on given directory.

sudo chown -R tomcat webapps/ work/ temp/ logs/



Step 6: Finding JAVA PATH  

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

sudo update-java-alternatives -l


Step 7: Run System Update & Upgrade 

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

sudo nano /etc/systemd/system/tomcat.service

Paste the following configuration.

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target


Step 8: Controlling Apache Tomcat Service 

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

To reload the new added service for tomcat.

sudo systemctl daemon-reload

To start the apache tomcat service.

sudo systemctl start tomcat

To check the apache tomcat service.

sudo systemctl status tomcat

To enable the apache tomcat service.

sudo systemctl enable tomcat


Step 9: Allowing Ports in UFW  

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

sudo ufw allow 8080


sudo ufw allow 8443


Aftab Ali

My expertise is in ethical hacking, penetration testing, network security, monitoring and more.

Post a Comment

Previous Post Next Post