Apache Tomcat or “Tomcat” is a free and open-source Java Servlet container for Java code and applications. It provides a “pure Java” HTTP server environment where Java code can run. Tomcat also implements JavaServer Pages, Java Expression Language, and WebSocket technologies.

In this guide, we’ll show you how to install Apache Tomcat 10 on the Debian 12 server. you will also learn how to set up Nginx as a reverse proxy for Apache Tomcat.

Prerequisites

To get started, make sure you have the following:

  • A Debian 12 server.
  • A non-root user with administrator privileges.

Installing Java OpenJDK

Apache Tomcat is mainly written in Java, so before installing it, you must install Java on your system. In this example, you will install Java OpenJDK 17, which is available by default on the Debian repository.

Before you start installing Java, update and refresh your Debian repository with the command below.

sudo apt update

<img alt="update repo" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/2-update-repo.png65e23fdba0a69.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="153" loading="lazy" src="data:image/svg xml,” width=”750″>

Now install the Java OpenJDK package to your Debian server using the following command. The default-jdk package refers to Java OpenJDK 17, which is the LTS version of Java.

sudo apt install default-jdk

Type y to confirm with the installation.

<img alt="install java" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/3-install-java.png65e23fdbe79bc.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="352" loading="lazy" src="data:image/svg xml,” width=”750″>

After installing Java, run the command below to verify your Java version. you will see that Java OpenJDK 17 is installed.

java --version

<img alt="check java" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/4-check-java.png65e23fdc0bc01.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="128" loading="lazy" src="data:image/svg xml,” width=”750″>

Installing Apache Tomcat via Repository

By default, the latest Debian 12 repository provides Apache Tomcat 10. If you need to install Apache Tomcat via APT, then this method is suitable for you.

First, check the tomcat10 package using the command below.

sudo apt info tomcat10

In the following output, you can see that Apache Tomcat 10 is available on the main Debian repository, in the section of java.

<img alt="check tomcat10" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/5-check-tomcat10.png65e23fdc57ade.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="507" loading="lazy" src="data:image/svg xml,” width=”750″>

If you want to install Tomcat via APT, run the command below on your system. Type y to confirm the installation.

sudo apt install tomcat10 tomcat10-common tomcat10-admin tomcat10-user tomcat10-examples

<img alt="install tomcat10" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/6-install-tomcat.png65e23fdc8ef24.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="254" loading="lazy" src="data:image/svg xml,” width=”750″>

Once the installation is complete, the tomcat10 service should be running. Verify it with the command below.

sudo systemctl is-enabled tomcat10

sudo systemctl status tomcat10

If the tomcat10 service running, you should get the following output:

<img alt="tomcat status" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/7-verify-tomcat9.png65e23fdcab19f.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="258" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, open your web browser and visit the server IP address with the default Tomcat port 8080 http://192.168.5.15:8080/. If your installation is successful, you should get the default index page of Apache Tomcat 10.

<img alt="tomcat index" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/1-check-tomcat-index.png65e23fdcc4a87.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="359" loading="lazy" src="data:image/svg xml,” width=”750″>

Installing Tomcat via Binary

Now if you want to install the latest package of Apache Tomcat, you can install it via binary package. In this section, you will learn how to do it on your Debian server.

First, create a new system user tomcat with the command below.

sudo useradd -m -u -d /opt/tomcat -s /usr/sbin/nologin tomcat

Visit the Apache Tomcat download page and check the latest version of Tomcat. Then run the command below to download the latest Apache Tomcat version.

export VERSION=10.1.19

wget https://www-eu.apache.org/dist/tomcat/tomcat-10/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz

Once downloaded, run the command below to create a new Apache Tomcat installation directory /opt/tomcat and extract the Tomcat binary package into it.

mkdir -p /opt/tomcat

sudo tar -xf apache-tomcat-${VERSION}.tar.gz -C /opt/tomcat

Now create a new symlink of the extracted Tomcat directory to /opt/tomcat/latest. Then, change the ownership of /opt/tomcat directory to the tomcat user.

sudo ln -s /opt/tomcat/apache-tomcat-${VERSION} /opt/tomcat/latest

sudo chown -R tomcat:tomcat /opt/tomcat

Next, create a new systemd service file /etc/systemd/system/tomcat.service using nano editor.

sudo nano /etc/systemd/system/tomcat.service

Paste the configuration below to set up the service file for Apache Tomcat.

[Unit]

Description=Tomcat 10 servlet container

After=network.target[Service]

Type=forking

User=tomcat

Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/default-java"

Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

Environment="CATALINA_BASE=/opt/tomcat/latest"

Environment="CATALINA_HOME=/opt/tomcat/latest"

Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"

Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX: UseParallelGC"

ExecStart=/opt/tomcat/latest/bin/startup.sh

ExecStop=/opt/tomcat/latest/bin/shutdown.sh

[Install]

WantedBy=multi-user.target

Save the file and exit the editor.

Run the command below to reload the systemd manager, then start and enable the tomcat service.

sudo systemctl daemon-reload
sudo systemctl start tomcat

sudo systemctl enable tomcat

<img alt="setup tomcat" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/8-setup-tomcat-service.png65e23fdcf34d6.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="217" loading="lazy" src="data:image/svg xml,” width=”750″>

Once started, verify the tomcat service using the command below. Make sure that your Tomcat service is running like the following.

sudo systemctl status tomcat

<img alt="verify tomcat" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/9-verify-tomcat-service.png65e23fdd18a38.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="222" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, open your web browser and visit http://192.168.5.15:8080/. If everything goes well, you should see the Apache Tomcat index page.

<img alt="tomcat index" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/10-tomcat-index.png65e23fdd55761.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="338" loading="lazy" src="data:image/svg xml,” width=”750″>

Creating Tomcat Administrator

At this point, you have installed Apache Tomcat on your Debian server. In the next step, you will set up authentication for Apache Tomcat and enable the Tomcat manager and host-manager.

To start, edit the Tomcat config file /etc/tomcat10/tomcat-users.xml using the following nano editor.

sudo nano /etc/tomcat10/tomcat-users.xml

Insert lines below between the ‘tomcat-users‘ section. Make sure to change the default username admin and the password tomcatadmin with your credentials.

<!--

user: admin pass: tomcatadmin

-->













Save and exit the file.

Now, open the config file for the Tomcat manager and host-manager using the nano editor.

sudo nano /usr/share/tomcat10-admin/host-manager/META-INF/context.xml

sudo nano /usr/share/tomcat10-admin/manager/META-INF/context.xml

Comment the line ‘<Valve className="org.apache.catalina.valves.RemoteAddrValve"' to allow access to the Tomcat manager and host-manager. By adding , the configuration will be disabled or commented.

<!--

<Valve className="org.apache.catalina.valves.RemoteAddrValve"

allow="127.d .d .d |::1|0:0:0:0:0:0:0:1" />

-->

Save the file and exit the editor.

Next, restart the tomcat service with the command below to apply the new Tomcat configuration.

sudo systemctl restart tomcat

Lastly, visit http://192.168.5.15:8080/manager to access the Tomcat manager, and http://192.168.5.15:8080/host-manager to access the Tomcat host manager. Input your admin user and password when prompted and click Sign in.

<img alt="tomcat login" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/11-login.png65e23fdd6ebee.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="384" loading="lazy" src="data:image/svg xml,” width=”750″>

If successful, you should see the Apache Tomcat manager dashboard.

<img alt="tomcat manager" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/12-tomcat-manager.png65e23fddc3193.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="445" loading="lazy" src="data:image/svg xml,” width=”750″>

For the Tomcat host-manager, below is what looks like:

<img alt="tomcat host manager" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/13-tomcat-hostmanager.png65e23fde3d6f6.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="350" loading="lazy" src="data:image/svg xml,” width=”750″>

Configuring Nginx as a Reverse Proxy

In this guide, you will run Apache Tomcat with Nginx as a reverse proxy. In this section, you will install nginx and set up a server block configuration as a reverse proxy for Tomcat that runs on port 8080.

Run the command below to install Nginx to your system. Type y to confirm the installation.

sudo apt install nginx

<img alt="install nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/17-install-nginx.png65e23fde59206.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="328" loading="lazy" src="data:image/svg xml,” width=”750″>

Once installation is complete, create a new server block configuration /etc/nginx/sites-available/tomcat.conf using nano editor.

sudo nano /etc/nginx/sites-available/tomcat.conf

Add the configuration below to set up Nginx as a reverse proxy for Apache Tomcat.

server {

listen 80;

server_name tomcat.hwdomain.io;

access_log /var/log/nginx/tomcat-access.log;

error_log /var/log/nginx/tomcat-error.log;

location / {

proxy_set_header X-Forwarded-Host $host;

proxy_set_header X-Forwarded-Server $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://127.0.0.1:8080/;

}

}

Save and exit the file when done.

Now, activate the server block configuration and verify your Nginx syntax. If everything goes well, you should get an output such as ‘test is successful – syntax is ok‘.

sudo ln -s /etc/nginx/sites-available/tomcat.conf /etc/nginx/sites-enabled/

sudo nginx -t

<img alt="setup nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/14-setup-server-block.png65e23fde791a2.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="141" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, restart the Nginx service to apply new changes and verify it to ensure the service is running.

sudo systemctl restart nginx

sudo systemctl status nginx

If Nginx is running, you should get the following output:

<img alt="verify nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/15-verify-nginx.png65e23fdeb1cd7.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="204" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, back to your web browser and visit http://tomcat.hwdomain.io/. You should see the default index page of Apache Tomcat.

<img alt="tomcat nginx reverse proxy" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/03/echo/16-nginx-server-block.png65e23fdeca6ed.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="322" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

Congratulations! You have now installed Apache Tomcat 10 on Debian 12 server. You have learned two methods for installing Apache Tomcat, via APT repository and manually via binary package. In the end, you also have learned how to set up Nginx as a reverse proxy for your Tomcat installation.