How to Install Apache Tomcat 10 on Debian 10

Install Apache Tomcat 10 on Debian 10 systems and deploy Java web applications without putting in much effort. It bags utilities like Java Servlet, JavaServer Pages, Java EL, providing an environment to invoke Java codes.

Apache Tomcat 10 or Tomcat is a Java-based web server and container designed to serve seamlessly and reader Java applications. With Tomcat, you’re looking at an open-source Java Servlet implementation that offers a list of striking features ranging from lightweight to high flexibility.

Released by the Apache Software Foundation to help systems execute various forms of Java utilities with ease. In the following tutorial, you’ll learn how to install Apache Tomcat 10 on Debian 10 system and proceed with the basic file configurations.

Install Apache Tomcat 10 on Debian 10

Prerequisites

Before installing Apache Tomcat 10, make sure you’ve got a running server on Debian 10, alongside a valid domain that is pointed with the server of your IP. It is also crucial to access a server configured with a root password.

Apart from that, there are some other prerequisites which include:

  • Sudo user privileges
  • System running Java 8 or higher version.
  • A VPS with at least 1 GB of RAM.

Install Apache Tomcat 10 on Debian 10: Getting Started

Get started with the installation of Tomcat 10 by checking the distribution of your OS. You can do that by launching the Terminal using the Ctrl+Alt+T key combination and running the following command

$ lsb_release -a
install tomcat 10 on debian 10

Once done, update your system packages to the latest version. Invoke the following commands and get the latest changes installed on your Debian 10 OS

$ sudo apt update -y && sudo apt upgrade -y

Install Java on your VPS

As already mentioned, the Apache Tomcat is a Java-based application. For that matter of fact, it is quite evident that you’ll need to install Java on your working server. 

Launch the Terminal

Run the following command:

$ sudo apt install default-jdk -y

After you’re done getting Java installed on your VPS, make sure to check the installed version.

Input:

java --version

Output:

installing java on your system

Installing Apache Tomcat 10 on Debian 10

Now that you’ve got the resources ready, it is time we start installing Apache Tomcat 10 on our Debian system.

Tomcat User Creation

The first thing to do is add a user to run Apache Tomcat. Creating a user is crucial to ensure that Apache Tomcat runs properly. Invoke the following command for doing that

useradd -m -d /opt/tomcat -U -s /bin/false tomcat

Download and Install Tomcat 10 on Debian 10

After you’ve successfully created a Tomcat user, you’ll need to visit the /opt directory on your server and get the latest version of Tomcat downloaded. You can do that from the official Apache website by using the wget flag.

Here is how the command should be like:

$ wget [link]

Getting the Downloaded File Extracted

Once downloaded, you know that the next step is to get the archived file extracted into a directory. Invoke a command similar to:

tar -xzvf apache-tomcat-10.0.10.tar.gz -C /opt/tomcat --strip-components=1


Wait for the extraction to complete, and after that, set the right set of “tomcat” permissions recursively on the created tomcat directory: For that, you’ll need to employ the chown command alongside the R flag in the following manner.

chown -R tomcat:tomcat /opt/tomcat/


It is also essential to set the executed permissions on the scripts located within the bin directory used for tomcat installation. Employ the chmod command for that.

chmod -R u+x /opt/tomcat/bin

Systemd Unit File for Tomcat

Navigating to the /opt/tomcat/bin, you’ll find the shell scripts that allow starting and stopping of Apache Tomcat. However, we don’t recommend opting for the manual approach of starting and stopping via these scripts on the bin file, rather make use of the system unit files. 

This will instruct the system to enable the Tomcat to start after system boot. For that, you’ll need to create a system file. Do that by simply pasting the following lines into it:

nano /etc/systemd/system/tomcat.service
system unit file for tomcat

Once done, the next thing to do is save the created file, close it, and then initiate the service.

systemctl start tomcat
systemctl enable tomcat

Make sure you verify that the service is up and running. For that, execute the following command:

systemctl status tomcat

Once you get the green signal, you’re ready to launch the Tomcat GUI in any of your web browsers through your server IP address and port 8080:

HTTP://[YOUR_IP_ADDRESS]:8080

Configuring Tomcat 10

configuring tomcat 10

Post-installation, you’ll have access to the Tomcat Manager, where you can easily manage various aspects of the applications. Bringing a very nice and intuitive GUI, the manager is very flexible to use. However, you’ll need to enable it by opening the file:

nano /opt/tomcat/conf/tomcat-users.xml

Now add the following lines just at the very bottom of the line. You can set the username and password values as desired

<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="admin" password="InputYourStrongPasswordHere" roles="manager-gui,admin-gui"/>

After that, make sure to save the file before eventually closing it. You’ll then need to allow WebApp and Host Managers access to Tomcat.

nano /opt/tomcat/webapps/manager/META-INF/context.xml

Next, comment out the following lines

<!-- 
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> 
-->
nano /opt/tomcat/webapps/host-manager/META-INF/context.xml
<!-- 
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> 
→

Finally, save the created files one more time, close them, and restart the Tomcat services. For that, run the following command:

$ systemctl restart tomcat

You can now access the manager app by refreshing the tomcat page and using the username and the password you set above. This will help make your system ready to deploy and run Java applications effortlessly.

install apache tomcat 10 on Debian 10

Getting Tomcat 10 Nginx Ready

At first, you should install the Nginx web server by invoking the following command:

apt-get install nginx -y

After that, you should create a new Nginx virtual host configuration file:

nano /etc/nginx/conf.d/tomcat.conf

Once done, add the following lines to it:

server {
isten 80;

  server_name tomcat.example.com;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/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 the file and close it. Finally, get the Nginx for any syntax error verified with the help of the following command:

nginx -t

And this is how you install Apache Tomcat 10 on Debian 10 system. We’ve walked you through the most detailed guide on getting the Apache Tomcat 10 ready for your system in this write-up. We’ve also discussed the various ways in which you can configure the Tomcat Manager and get the utility ready.

If this guide helped you, please share it.

Leave a Reply
Related Posts