In this tutorial, we will show you how to install Apache Tomcat on Debian 11. For those of you who didn’t know, Apache Tomcat is an open-source web server, that allows you to execute java code. It can execute Java-related technologies such as Java Servlet, JSP, Java Expression Language, and many more.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of the Apache Tomcat on a Debian 11 (Bullseye).
Prerequisites
- A server running one of the following operating systems: Debian 10 or Debian 11.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Install Apache Tomcat on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt
commands in the terminal:
sudo apt update sudo apt upgrade
Step 2. Installing Java.
Now we will install the package of Java, as we know Tomcat is written in Java, so Java is a prerequisite of Apache Tomcat, so for its installation, execute the command:
sudo apt install openjdk-11-jdk
Verify the Java version using this command:
java -version
Step 3. Installing Apache Tomcat on Debian 11.
By default, Apache Tomcat is not available on Debian 11 base repository. So, now run the following command below to download the Apache Tomcat package from the official page:
wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.17/bin/apache-tomcat-10.0.17.tar.gz
Next, extract the downloaded Tomcat Tar file:
sudo tar -zxvf apache-tomcat-*.tar.gz sudo mv apache-tomcat-*/* /opt/tomcat/
After that, change the ownership of the directory to allow the tomcat user to write files to it:
sudo chown -R tomcat:tomcat /opt/tomcat/
Step 4. Create Systemd File for Apache Tomcat.
Now Create a Tomcat systemd
service file:
sudo nano /etc/systemd/system/tomcat.service
Add the following file:
[Unit] Description=Apache Tomcat 9.x Web Application Container Wants=network.target After=network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/ Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid Environment=CATALINA_HOME=/opt/tomcat Environment='CATALINA_OPTS=-Xms512M -Xmx1G -Djava.net.preferIPv4Stack=true' Environment='JAVA_OPTS=-Djava.awt.headless=true' ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh SuccessExitStatus=143 User=tomcat Group=tomcat UMask=0007 RestartSec=10 Restart=always [Install] WantedBy=multi-user.target
Save and close the file, then reload systemd
daemon:
sudo systemctl daemon-reload sudo systemctl start tomcat sudo systemctl enable tomcat
Step 5. Configure Apache Tomcat.
We will provide its access to the user by configuring its XML file with the help of a nano editor:
sudo nano /opt/tomcat/conf/tomcat-users.xml
Add the following lines:
rolename="admin-gui,manager-gui"/> <user username="admin" password="password" roles="manager-gui,admin-gui"/>
Save and close the file, then restart the service by using the systemctl
command:
sudo systemctl restart tomcat
Step 6. Configure Firewall.
By default, the UFW firewall is enabled on Debian. Depending on your Apache Tomcat configuration file, open port 8080 to allow traffic:
sudo ufw allow 8080/tcp sudo ufw reload
Step 7. Accessing Apache Tomcat Web Interface.
Once successfully installed, open your web browser and access the Apache Tomcat using the URL http://your-IP-address:8080
. You will get the following screen:
Congratulations! You have successfully installed Apache Tomcat. Thanks for using this tutorial for installing the latest version of the Apache Tomcat on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Apache website.