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
Apache Tomcat installed on Ubuntu 20.04
Apache Tomcat installed on Ubuntu 20.04
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed or upgraded Ubuntu 20.04 Focal Fossa
Software Apache Tomcat
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

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.

  1. First, open a terminal and download the latest package information with the following command:
    $ sudo apt update
    
  2. Next, check the repository to see what Tomcat package is available for download:
    $ sudo apt-cache search tomcat
    
    We see in the screenshot below that the tomcat9 package is what we have available for download.
    Searching Ubuntu software repository for tomcat packages
    Searching Ubuntu software repository for tomcat packages
  3. Begin downloading and installing the tomcat9 and tomcat9-admin packages (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
    
  4. After Tomcat has finished installing, it should start up automatically. You can verify it running with the ss command. You should see an open port, number 8080, as that is the default port for Apache Tomcat.
    $ ss -ltn
    
    The ss command indicates that port 8080 is listening for incoming connections from any source
    The ss command indicates that port 8080 is listening for incoming connections from any source
  5. 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 8080:

$ 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: http://127.0.0.1:8080

Apache Tomcat is running and is connectable from a browser
Apache Tomcat is running and is connectable from a browser

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.

  1. First, use nano or your preferred text editor to open the tomcat-users.xml file. 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
    
  2. Inside this file, paste the following three lines above the tag. This will create a new user called tomcat with 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"/>
    Editing the tomcat-users XML file with user credentials to access the admin GUI
    Editing the tomcat-users XML file with user credentials to access the admin GUI
  3. Save and close the file, then restart Tomcat Server:
    $ sudo systemctl restart tomcat9
    

Access Tomcat Web Application Manager

  1. Navigate to http://127.0.0.1:8080/manager/html to access the Tomcat Web Application Manager. You should be prompted for the credentials we just configured.
    Logging into the Tomcat Web Application Manager
    Logging into the Tomcat Web Application Manager
  2. Once you login with the credentials, you should be presented with the Tomcat Web Application Manager's main page.
    Successful connection to the Tomcat Web Applcation Manager
    Successful connection to the Tomcat Web Applcation Manager

We're all done. From inside this admin panel, you'll be able to configure virtual hosts and other settings.

Conclusion

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.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions