X

How to Install Apache Tomcat 10 on Debian 10

Spread the love

If you ever wondered how to install Apache Tomcat 10, and how to configure it on Debian 10 then you are at the right place. In this tutorial, we are going to cover every step needed to install the latest version on Tomcat 10 with all requirements

Apache Tomcat 10 or simply Tomcat 10 is a Java application server used to render the Java web pages. It is an open-source software developed by the Apache Software Foundation responsible to execute Java servlets and render the Java web pages as mentioned above.

Apache Tomcat 10 is compatible with multiple distributions of Linux as Ubuntu, CentOS, and Debian. Installing Tomcat 10 on Debian is very easy and will take less than 15 minutes with all requirements and configuration files.

Let’s start with the installation on Debian 10!

 

Prerequisites

  • Fresh install of Debian 10
  • User privileges: root or non-root user with sudo privileges
  • Java 8 or higher version.
  • VPS with at least 1GB of RAM

Check the distribution of your OS on your server before the installation.

lsb_release -a

The out should be similar to this:

root@vps:~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster

1. Updating the System

Execute the commands below to get the latest changes on your Debian 10 OS.

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

2. Install Java

Apache Tomcat is based on Java, and that is why we need to install it first on the VPS:

sudo apt install default-jdk -y

Check the installed version with the following command:

java --version

The output should be similar to this:

root@vps:~# java --version
openjdk 11.0.12 2021-07-20
OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2deb10u1, mixed mode, sharing)

3. Tomcat User Creation

In order for Apache Tomcat to run propely we need to create user:

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

4. Downloading and installing Tomcat 10

First, go in /opt directory on your server (cd /opt) and then download the Tomcat within. Tomcat 10 can be downloaded from the official Apache website with the command below:

wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.10/bin/apache-tomcat-10.0.10.tar.gz

The next, step is to extract the archived file into a directory.

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

Once, the extraction is completed, set the right “tomcat” permissions recursively on the tomcat directory:

chown -R tomcat:tomcat /opt/tomcat/

Also, set the execute permissions on scripts in the bin directory of the tomcat installation:

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

5. Systemd Unit File for Tomcat

In the bin directory of Tomcat at /opt/tomcat/bin there are shell scripts for starting and stopping Tomcat. It is not recommended to start and stop Tomcat manually via these scripts thus it is recommended via system unit files. This way Tomcat will be able to start after system boot. Create a systemd file and paste the following lines into it:

nano /etc/systemd/system/tomcat.service
[Unit]
Description="Tomcat Service"
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
[Install]
WantedBy=multi-user.target

Save the file, close it and start the service.

systemctl start tomcat
systemctl enable tomcat

To check if the service is up and running execute the command:

systemctl status tomcat

The output will be similar to this:

root@vps:~# systemctl status tomcat
● tomcat.service - "Tomcat Service"
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
Active: active (running) since Thu 2021-08-12 03:54:54 EDT; 4min 27s ago
Process: 17708 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 17715 (java)
Tasks: 32 (limit: 4700)
Memory: 236.0M
CGroup: /system.slice/tomcat.service
└─17715 /usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java -Djava.util.logging.config.file=/opt/tomcat/conf/logging.properties -Djava.util.logging.manager=org.a

Now you can open the Tomcat GUI in your web browser via your server IP address and port 8080:

http://YOUR_IP_ADDRESS:8080

6. Configuration of Tomcat

Tomcat Manager is a place when you can easily deploy, list, and manage your applications. It has a nice GUI and is very intuitive to use. Later, you will need access to Tomcat Manager and in this step, we are going to enable it. Open the file:

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

And, add the following lines at the bottom before the line “”:

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

Save the file and close it. Now we need to allow access to Tomcat for WebApp and Host Managers:

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

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" /> 
-->

Save the files close it and restart the tomcat service:

systemctl restart tomcat

Now, refresh the tomcat page and you will be able to access the Manager App at http://162.246.248.185:8080/manager/html with the username and password set above. Congratulations! You successfully installed and configured Tomcat 10 on Debian 10. Now you can easily deploy Java applications and make them run in no time. Of course, if you find some difficulties while installing the app you do not have to install it by yourself. You can always contact our system admins and with their expertise, they will install Tomcat 10 for you. All you need to do is order an SSD VPS plan and contact our support. We are available 24/7.

PS. If you liked this post, on how to install Apache Tomcat 10 on Debian 10, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Categories: Debian Tutorials
admin:
Related Post