Apache Tomcat is an HTTP server that can run Java technologies, namely Java Servlet, JavaServer Pages (JSP), and Java Expression Language. In this guide, we'll show you how to install Apache Tomcat on Ubuntu 20.04 Focal Fossa. We'll also cover the steps to set up a user for accessing the application manager, which is a panel inside Tomcat that can configure virtual hosts and other applications.In this tutorial you will learn:
- How to install and configure Apache Tomcat
- Open firewall ports for Tomcat and test
- How to configure credentials for Tomcat admin
- How to access Tomcat Web Application Manager
|Category||Requirements, Conventions or Software Version Used|
|System||Installed or upgraded Ubuntu 20.04 Focal Fossa|
|Other||Privileged access to your Linux system as root or via the
# - requires given linux commands to be executed with root privileges either directly as a root user or by use of
How to install Tomcat Server
The easiest way to install Tomcat Server is from Ubuntu's default software repository. The repository should contain the latest stable version of Tomcat.
- First, open a terminal and download the latest package information with the following command:
$ sudo apt update
- Next, check the repository to see what Tomcat package is available for download:
$ sudo apt-cache search tomcatWe see in the screenshot below that the
tomcat9package is what we have available for download.
- Begin downloading and installing the
tomcat9-adminpackages (or whatever the current name/version of the packages are at the time of your reading this) and their dependencies with this command:
$ sudo apt install tomcat9 tomcat9-admin
- After Tomcat has finished installing, it should start up automatically. You can verify it running with the
sscommand. You should see an open port, number
8080, as that is the default port for Apache Tomcat.
$ ss -ltn
- Tomcat should continue to start up automatically when Ubuntu reboots. You can change this behavior at any time by disabling or enabling it:
$ sudo systemctl enable tomcat9 OR $ sudo systemctl disable tomcat9
Open firewall ports for Tomcat Server
If the UFW firewall is running on your system, external devices are going to have trouble connecting to your Tomcat server. Type the following command to allow incoming TCP traffic from any source to port
$ sudo ufw allow from any to any port 8080 proto tcp
Test Tomcat Server
With Tomcat up and running, you should now be able to access it in a web browser. You can connect to it via your system's loopback address and specifying Tomcat's port number:
If you see the "It works!" page, then Tomcat is accessible and running correctly.
Create user for Web Application Manager
In order to access Tomcat's web application manager (the admin configuration panel inside Tomcat), we'll need to set up a new Tomcat user.
- First, use nano or your preferred text editor to open the
tomcat-users.xmlfile. Note that the directory name for us is "tomcat9" since that is the current version of Tomcat. Yours may be different.
$ sudo nano /etc/tomcat9/tomcat-users.xml
- Inside this file, paste the following three lines above the
tag. This will create a new user called
tomcatwith a password of
pass. Substitute your own values there.
<role rolename="admin-gui"/> <role rolename="manager-gui"/gt; <user username="tomcat" password="pass" roles="admin-gui,manager-gui"/>
- Save and close the file, then restart Tomcat Server:
$ sudo systemctl restart tomcat9
Access Tomcat Web Application Manager
- Navigate to
http://127.0.0.1:8080/manager/htmlto access the Tomcat Web Application Manager. You should be prompted for the credentials we just configured.
- Once you login with the credentials, you should be presented with the Tomcat Web Application Manager's main page.
We're all done. From inside this admin panel, you'll be able to configure virtual hosts and other settings.
Deploying Apache Tomcat on Ubuntu 20.04 Focal Fossa is a great way to host your Java HTTP web server. Website administrators use it to run Java Servlets, JavaServer Pages, and Java Expression Language. Setting up Tomcat on Ubuntu is relatively easy and the admin package extends its functionality by providing an easy web interface for managing your server configuration.