Apache Tomcat is an open-source web application server optimized for serving Java-based content. Tomcat is used to run Java Servlets and serve web pages that contain JavaServer Pages (JSP) code.
This guide covers the installation of Apache Tomcat 9 server on Ubuntu 20.04.
A user with sudo capability on Ubuntu 20.04.
Install Apache Tomcat 9 on Ubuntu
Begin by updating available packages on your Ubuntu 20.04 system with the command below.
$ sudo apt update
Next, run the command below to install Apache Tomcat 9 and related packages.
$ sudo apt install tomcat9 tomcat9-admin
Enter y to confirm the installation when prompted.
After you have successfully installed tomcat9, run the next command to confirm that the service is active.
$ sudo systemctl status tomcat9
Press q to return to the command prompt.
Note: If the tomcat9 service is not already running, start it with the command below.
$ sudo systemctl start tomcat9
To configure the Apache Tomcat service to start automatically when the system boots, run the next command.
$ sudo systemctl enable tomcat9
Test the Apache Tomcat 9 Service
Firstly, let us confirm what port the Apache Tomcat 9 service is listening on. Run the command below to do that.
$ sudo netstat -tulpn
Note: If the netstat tool is not available on your Ubuntu 20.04 machine, you can install it with:
$ sudo apt install net-tools
As shown in the image below, the Apache Tomcat 9 service is listening on port 8080. You can tell by the program name “java.”
By default, Apache Tomcat uses port 8080 because of the possibility that a web server might already be running on port 80.
Note: If you wish to change the default listening port from 8080 to something else, edit the following configuration file and replace 8080 accordingly. You would need to restart tomcat9 for the changes to take effect.
$ sudo nano /usr/share/tomcat9/etc/server.xml
In this guide, we are using the default listening port 8080.
If applicable, update your firewall rules to allow inbound traffic on port 8080. For example, if UFW is enabled, run the command below to allow incoming traffic on port 8080.
$ sudo ufw allow 8080
Now, open a web browser and enter YourServerIP:8080. For instance, 192.168.16.8:8080.
You should see the default Tomcat home page as shown in the image below.
Login to the Apache Tomcat Manager Webapp
The Tomcat Manager Webapp is used to manage the Tomcat server via a graphical interface. First, let us create a user as follows.
$ sudo nano /etc/tomcat9/tomcat-users.xml
Second, copy and paste the following three lines within the <tomcat-users> </tomcat-users>.tags. Remember to replace shola and tomcatP@ss with your own values.
<role rolename="admin-gui"/> <role rolename="manager-gui"/> <user username="shola" password="tomcatP@ss" roles="admin-gui,manager-gui"/>
Next, save changes and close the file.
Restart tomcat9 with:
$ sudo systemctl restart tomcat9
Now, go back to the default Tomcat home page and click the manager_webapp link or the host-manager_webapp link.
After that, login using the Tomcat credentials specified earlier.
You can now easily manage your Tomcat instance from the web application manager page. Click HTML Manager Help or Manager Help at the top if you need further guidance.
In this guide, we covered the installation of Apache Tomcat 9 on Ubuntu 20.04. We also described how to access the Tomcat Web Application Manager in order to manage your Tomcat instance. Comments and questions are welcome.