Apache Tomcat is an open-source Java Servlet implementation developed by the Apache Software Foundation.

Besides Java Servlets, Tomcat implements several other Java server technologies, including  JavaServer Pages (JSP), Java Expression Language, and Java WebSocket.

Apache Tomcat provides an HTTP Web Server for Java applications with support for HTTP/2, OpenSSL for JSSE, and TLS virtual hosting.

This tutorial will show you how to install Apache Tomcat on the Debian Buster 10. This guide covers some topics, including the Java OpenJDK and JRE installation, running Apache Tomcat as a service, and setting up Apache Tomcat authentication.

Prerequisites

  • Debian 10 server
  • 2GB RAM (more)
  • Root privileges

What we will do?

  • Install Java OpenJDK and JRE on Debian 10
  • Setup $JAVA_HOME Environment
  • Download and Install Apache Tomcat
  • Testing Apache Tomcat
  • Setup Apache Tomcat as a Service
  • Setup Apache Tomcat Authentication
  • Testing

Step 1 – Install Java OpenJDK and JRE on Debian 10

First, we will install Java OpenJDK and JRE to Debian 10. It’s available by default on the Debian repository, which is the latest version of Java 11 LTS.

Install Java OpenJDK and JRE on the Debian system using the apt command below.

sudo apt install default-jdk default-jre

Once the installation is complete, check the Java version using the following command.

java -version

As a result, java OpenJDK and JRE have been installed on the Debian Buster 10.

How to Install Apache Tomcat on Debian Debian linux

Step 2 – Setup $JAVA_HOME Environment

After installing java OpenJDK, we will set up the ‘$JAVA_HOME’ environment variable. The Debian system’s default path directory is located at the ‘/usr/lib/jvm/default-java’ directory.

Now edit the ‘/etc/environment’ configuration using vim editor.

vim /etc/environment

Paste the ‘$JAVA_HOME’ variable as below.

JAVA_HOME="https://vitux.com/usr/lib/jvm/default-java"

Save and close.

Next, edit the ‘~/.profile’ configuration.

vim ~/.profile

Paste the following configuration into it.

export JAVA_HOME=/usr/lib/jvm/default-java
export PATH=$JAVA_HOME/bin:$PATH

Save and close.

After that, reload the ‘~/.profile’ file and apply the new configuration.

source ~/.profile

The ‘$JAVA_HOME’ environment variable has been configured. Check it using the command below.

echo $JAVA_HOME
echo $PATH

As a result, you will get the ‘$JAVA_HOME’ environment variable which is located in the ‘/usr/lib/jvm/default-java’ directory. Also, you will get the java binary path at the ‘$JAVA_HOME/bin’ directory.

How to Install Apache Tomcat on Debian Debian linux

Step 3 – Download and Install Apache Tomcat

In this step, we will create a new system user and download the Apache Tomcat binary.

Add a new group and user named ‘tomcat’ using the command below.

groupadd tomcat
useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Now go to the ‘/opt’ directory and download the latest version of Apache Tomcat using the wget command.

cd /opt/
wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.31/bin/apache-tomcat-9.0.31.tar.gz

How to Install Apache Tomcat on Debian Debian linux

Extract the Apache Tomcat compressed file and enable the directory to ‘tomcat’.

tar -xf apache-tomcat-9.0.31.tar.gz
mv apache-tomcat-9.0.31/ tomcat/

Now change the ownership of ‘/opt/tomcat’ directory to the ‘tomcat’ user.

chown -hR tomcat:tomcat tomcat

Apache Tomcat is now installed on Debian 10, located at the ‘opt/tomcat’ directory under the ownership of ‘tomcat’ user.

How to Install Apache Tomcat on Debian Debian linux

Step 4 – Testing

In step 3, we installed and configured tomcat. In this step, we want to run a short test to ensure no errors.

Go to the tomcat/bin directory and run the command ‘startup.sh’ to test Apache Tomcat.

cd /opt/tomcat/bin/
./startup.sh

Make sure the result is ‘Tomcat started’.

How to Install Apache Tomcat on Debian Debian linux

Tomcat is using port 8080 now. Open your web browser and type the server IP address followed by the default tomcat port ‘8080’.

http://10.5.5.45:8080/

You will get the default Apache Tomcat page as below.

How to Install Apache Tomcat on Debian Debian linux

Stop the Apache Tomcat using the following command and make sure the ‘tomcat’ user owns the ‘/opt/tomcat’ directory.

./shutdown.sh
chown -hR tomcat:tomcat /opt/tomcat/

As a result, the Apache Tomcat is installed on the Debian Buster 10. It can be run manually through the ‘start.sh’ script.

How to Install Apache Tomcat on Debian Debian linux

Step 5 – Setup Apache Tomcat as a Service

In this tutorial, we will run the Apache Tomcat as a systemd service. So we need to create a new systemd service file named ‘tomcat.service’.

Go to the ‘/etc/systemd/system’ directory and create a new service file ‘tomcat.service’.

cd /etc/systemd/system/
vim tomcat.service

Paste the following configuration into it.

[Unit]
Description=Apache Tomcat 8 Servlet Container
After=syslog.target network.target
 
[Service]
User=tomcat
Group=tomcat
Type=forking
Environment=CATALINA_PID=/opt/tomcat/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure
 
[Install]
WantedBy=multi-user.target

Save and close.

Now reload the systemd manager.

systemctl daemon-reload

Start the Apache Tomcat service and add it to the system boot.

systemctl start tomcat
systemctl enable tomcat

How to Install Apache Tomcat on Debian Debian linux

The Apache Tomcat is now up and running as a systemd service, check it using the following command.

netstat -plntu
systemctl status tomcat

As a result, the Apache Tomcat is running on default port ‘8080’ on the Debian Buster 10.

How to Install Apache Tomcat on Debian Debian linux

Step 6 – Setup Authentication

In this step, we will configure the users for Apache Tomcat. Tomcat is installed, and it’s running by default on port 8080, we can access it with a web browser, but we can not access the site-manager dashboard yet. To enable and configure Tomcat users, edit the file ‘tomcat-users.xml’.

Go to the tomcat configuration directory and edit the tomcat-users.xml file with vim.

cd /opt/tomcat/conf/
vim tomcat-users.xml

Add a new user ‘admin’ with password ‘password’ under the ‘tomcat-users’ configuration as below.

<tomcat-users
...


...

Save and close.

Next, go to the Tomcat manager directory and edit the context.xml file.

cd /opt/tomcat/webapps/manager/META-INF/
vim context.xml

Comment out the ‘className=”org.apache.catalina.valves.RemoteAddrValve”‘ as below.

<!--   -->
...

Save and close.

Now go to the host-manager directory and edit the context.xml file again.

cd /opt/tomcat/webapps/host-manager/META-INF/
vim context.xml

Comment out the ‘className=”org.apache.catalina.valves.RemoteAddrValve”‘ as below.

<!--   -->
....

Save and close.

Now restart the Apache Tomcat service using the following command and make sure there is no error.

systemctl restart tomcat

As a result, the Apache Tomcat Authentication has been enabled. You can log in to the Tomcat Manager and Host using the default user ‘admin’ with the password ‘password’.

How to Install Apache Tomcat on Debian Debian linux

Step 7 – Testing

In this step, we will test the Apache Tomcat installing. Also, we will test the Apache Tomcat Authentication against the web application manager and virtual host manager.

Apache Tomcat Index

Open your web browser and type the server IP address with port ‘8080’.

http://10.5.5.45:8080/

You will get the default index of Apache Tomcat as below.

How to Install Apache Tomcat on Debian Debian linux

Authentication Tomcat Web Application Manager

Now click on the ‘Manager App’ on the index menu, and you will be prompted for the authentication.

Type your default ‘admin’ user with the password ‘password’, and you will be redirected to the Tomcat web application manager as below.

How to Install Apache Tomcat on Debian Debian linux

As a result, you’ve successfully logged in to the Tomcat web application manager with a user that just configurated on top.

Authentication Tomcat Virtual Host Manager

Return to the home index Apache Tomcat and click the ‘Host Manager’ menu.

Type your default ‘admin’ user with the password ‘password’, and you will be redirected to the Tomcat Virtual Host Manager as below.

How to Install Apache Tomcat on Debian Debian linux

As a result, you’ve successfully logged in to the Tomcat Virtual Host manager with a user that just configured on top.

Finally, the installation and configuration of Apache Tomcat on Debian Buster 10 has been completed successfully.