How to Install Apache Tomcat11(version 11.0.2) on ubuntu.

How to Install Apache Tomcat11(version 11.0.2) on ubuntu.

What is tomcat?

Apache Tomcat is a free, open-source web server and servlet container that’s used to host Java-based web applications. Apache Tomcat (called “Tomcat” for short) is a free and open-source implementation of the Jakarta Servlet, Jakarta Expression Language, and WebSocket technologies. It provides a “pure Java” HTTP web server environment in which Java code can also run.

How Does Tomcat Work? 

Tomcat follows a modular architecture comprising connectors, containers, and the Catalina Servlet container. This architecture enables Tomcat to efficiently handle client requests and generate responses. Tomcat implements the Java Servlet and JavaServer Pages (JSP) specifications. It manages the lifecycle of servlets, loading and unloading them as needed.

Now, will create tomcat on ubuntu instance.

STEP 1:Create a EC2 instance (ubuntu machine).

Screenshot 2025 01 07 211259

STEP 2: Accessing instance with SSH.

Screenshot 2025 01 07 211452

STEP 3: Install Java.

Tomcat requires Java to run. You’ll need at least JDK 11 for Tomcat 11. You can install OpenJDK using the following commands:

sudo apt update 
sudo apt install openjdk-17-jdk -y 
java -version
Screenshot 2025 01 07 215817
Screenshot 2025 01 07 215943
Screenshot 2025 01 07 215956

STEP 4: Create a directory named tomcat in the /opt folder.

sudo mkdir /opt/tomcat
cd /opt/tomcat

STEP 5: Download Apache Tomcat
Navigate to the /opt directory and download Tomcat 11.0.2 using wget.

Use the following link for tar.gz file. https://downloads.apache.org/tomcat/tomcat-11/v11.0.2/

https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.2/bin/apache-tomcat-11.0.2.tar.gz
Screenshot 2025 01 07 212835

STEP 6: Extract the Tarball
Extract the downloaded tar.gz file.

<br>sudo tar -xvzf apache-tomcat-11.0.2.tar.gz
Screenshot 2025 01 07 214327

STEP 7: Rename the Tomcat Directory (Optional)
You may want to rename the Tomcat folder for easier access:

sudo mv apache-tomcat-11.0.2 tomcat

STEP 8: If you want Tomcat to start automatically on boot, you can create a systemd service file. Create a file named tomcat.service.

sudo nano /etc/systemd/system/tomcat.service
Screenshot 2025 01 07 221400

STEP 9: Add the following configuration (adjust paths and user accordingly).

ini 
[Unit] 
Description=Apache Tomcat Web Application Container 
After=network.target 
[Service] 
Type=simple 
User=username 
Group=username 
Environment=CATALINA_HOME=/opt/tomcat 
Environment=JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 
ExecStart=/opt/tomcat/bin/startup.sh 
ExecStop=/opt/tomcat/bin/shutdown.sh 
[Install] 
WantedBy=multi-user.target 
Screenshot 2025 01 07 221346

STEP 10: Start the tomcat server.

sudo systemctl daemon-reload
sudo systemctl enable tomcat
suto systemctl start tomcat
Screenshot 2025 01 07 221554

STEP 11: Go to instance and edit inbound rules.

Add the port number 8080 for tomcat.

Screenshot 2025 01 07 221639

STEP 12: Go to your browser type http://<Public IP address>:8080

  • You will see the tomcat dashboard.
WhatsApp Image 2025 01 07 at 22.20.15 482b029f

Conclusion.

You have successfully installed Apache Tomcat 11.0.2 on Ubuntu! You can deploy your web applications to the webapps directory in the Tomcat installation directory. Nowadays, Apache Tomcat is widely used by many companies as it implements many of the Jakarta EE specifications, such as: Java Servlet. JavaServer Pages. Java Expression Language.

Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *