Installing Apache Tomcat on Debian 10

Select distribution:
Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Apache Tomcat is an open-source software implementation of the Java Servlet and Java Server Pages technologies. With this guide, you’ll run applications within Tomcat using the OpenJDK implementation of the Java development environment.

Before You Begin

  1. Ensure that your system is up to date and that you have completed the Setting Up and Securing a Compute Instance . If you are new to Linux server administration, we recommend reviewing our beginner’s guide and the article concerning systems administration basics .

  2. Make sure you’ve followed our instructions for setting your hostname . Issue the following commands to make sure it is set properly:

    hostname
    hostname -f
    

    The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).

  3. You should also make sure your system is up to date. Enter the following command and install any available updates:

    apt-get update && apt-get upgrade
    
Note
The steps in this guide require root privileges. Be sure to run the steps below as root or with the sudo prefix. For more information on privileges see our Users and Groups guide.

Install Apache Tomcat

  1. Install Tomcat from the Debian repository:

    sudo apt-get install tomcat9
    
    Note
    OpenJDK will be installed as a dependency when you install the tomcat9 package. The package openjdk-11-jre-headless is included with the default-jre-headless metapackage in Ubuntu.
  2. You may also want to install the tomcat9-docs, tomcat9-examples, and tomcat9-admin tools which provide web-based applications that document, test, and allow you to administer Tomcat. You can install all three with the following command:

    sudo apt-get install tomcat9-docs tomcat9-examples tomcat9-admin
    
  3. Start the Tomcat service.

    sudo systemctl start tomcat9
    
  4. If you need to stop or restart Tomcat you can use the following commands, respectively:

    sudo systemctl stop tomcat9
    sudo systemctl restart tomcat9
    

Test and Use Tomcat

You can test your Tomcat installation by pointing your browser at your domain name, specifying port 8080. For example, you might use http://example.com:8080/, replacing example.com with your domain name. Note that Tomcat listens on network port 8080 and does not accept forced HTTPS connections by default. By default, Tomcat configuration files are located in the /var/lib/tomcat9/conf directory.

Configure tomcat9-admin (optional)

If you installed the tomcat9-admin web application above, you can configure it by adding the following lines to the end of your /var/lib/tomcat9/conf/tomcat-users.xml file before the </tomcat-users> line, substituting your own username and secure password. If using Tomcat Admin, include both the “manager-gui” role for the manager and the “admin-gui” role for the host-manager application.

File: /var/lib/tomcat9/conf/tomcat-users.xml
1
2
3
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="username" password="password" roles="manager-gui,admin-gui"/>
Note
If you are not using the web application and plan to manage your application(s) from the command line only, you should not enter these lines, because doing so may expose your server to unauthorized login attempts.

Restart the Tomcat server, which will allow these changes to take effect:

sudo systemctl restart tomcat9

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.