Ubuntu

How to Install Apache Tomcat Server on Ubuntu 22.04

According to a recent study by BZ Research, Apache Tomcat is the most used application server among Java developers. The survey states that Apache Tomcat Server is utilized by 64% of corporate Java engineers. Also, the Tomcat container has received more popularity and support from developers and system administrators than other application servers because of its session replication, clustering functionality, and JMX-based server monitoring and control.

This write-up will discuss the procedure to install Apache Tomcat Server on Ubuntu 22.04. So, let’s start!

How to Install Apache Tomcat Server on Ubuntu 22.04

To install Apache Tomcat Server on Ubuntu 22.04, you must follow the below-given step-by-step instructions.

Step 1: Update system repositories

Press “CTRL+ALT+T” to open the terminal of your Ubuntu 22.04 and run the below-given command to update system repositories:

$ sudo apt update

Step 2: Installation of Java

Before jumping into the installation of Apache Tomcat Server, it is essential to have “Java” on your system. For this purpose, execute the following command to install “OpenJDK 11”:

$ sudo apt install openjdk-11-jdk

Then, verify the version of the installed Java:

$ java version

Step 3: Check the availability of Apache Tomcat package

After fulfilling the requirements, check the availability of the Apache Tomcat package in the repository:

$ sudo apt-cache search tomcat

The given output signifies that the “tomcat9package for download:

Step 4: Install Apache Tomcat Server on Ubuntu 22.04

After finding the required Apache Tomcat package, we will install it on Ubuntu 22.04 with the help of the below-given command:

$ sudo apt install tomcat9 tomcat9-admin

Press “y” to permit the installation for a few minutes:

Step 5: Check ports for Apache Tomcat Server

On Ubuntu 22.04, the Apache Tomcat Server automatically starts working after completing the installation. To validate this operation, you can utilize the “ss” command for displaying the network socket related information:

$ ss -ltn

The default port for the Apache Tomcat server is “8080” and it can be seen in the following output that port “8080” is listening for all incoming connections:

Step 6: Open ports for Apache Tomcat Server

In case if the UFW firewall is activated on your system, then it may cause trouble while connecting external devices. So, to permit the incoming from any type of source to port “8080”, write out the following “ufw” command:

sudo ufw allow from any to any port 8080 proto tcp

Step 7: Test working of Apache Tomcat Server

If you have carefully followed all of the previous given, then at this point, the Apache Tomcat Server should be running on Ubuntu 22.04. To test its working specify your system loopback address with the number of the opened port for Apache Tomcat Server:

http://127.0.0.1:8080

How to use Apache Tomcat Web Application Manager on Ubuntu 22.04

Before using Apache Tomcat Web application manager, it is required to set up a new Tomcat user.

Step 1: Creating Tomcat user

Firstly, open up the “tomcat-users.xml” file in the “nano” editor:

$ sudo nano /etc/tomcat9/tomcat-users.xml

Your “tomcat-users.xml” file will somehow look like this:

Now, paste the following lines in the opened “tomcat-users.xml” file to create a new user named “tomcat” with the password “helloworld” having “admin-gui” and “manager-gui” roles:

<role rolename="admin-gui"/>

<role rolename="manager-gui"/gt;

<user username="tomcat" password="pass" roles="admin-gui,manager-gui"/>

Press “Ctrl+O” to save the added changes:

Step 2: Restart Tomcat Server

After creating a Tomcat account, restart the Apache Tomcat Server:

$ sudo systemctl restart tomcat9

Step 3: Open Tomcat Web Application Manager

Lastly, navigate to the following link for accessing the Tomcat Web Application Manager. You will be asked to input the credentials for accessing the created user account:

http://127.0.0.1:8080/manager/html

Enter the “username” and “password” which you have specified in the “tomcat-users.xml” file and click “Sign in”:

Congratulations! Now you can now access the Tomcat Web Application Manager via the tomcat user account:

We have compiled the method to install Apache Tomcat Server and use its application manager on Ubuntu 22.04.

Conclusion

To install Apache Tomcat Server on Ubuntu 22.04, install OpenJDK with the help of the “$ sudo apt install openjdk-11-jdk” command and execute the “$ sudo apt install tomcat9 tomcat9-admin” command for the Tomcat installation. After that, test the working of the Tomcat Server by navigating to the “http://127.0.0.1:8080” link. You can also create a user account to explore the web application manager of Apache Tomcat Server. This write-up discussed the method to install Apache Tomcat Server on Ubuntu 22.04.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.