In this tutorial, we will show you how to install and configuration of Apache Tomcat on Debian 10. For those of you who didn’t know, Apache Tomcat is an open-source web server and servlet container developed by the Apache Software Foundation. It implements the Java Servlet, JavaServer Pages (JSP), Java Unified Expression Language, and Java WebSocket specifications from Sun Microsystems and provides a web server environment for Java code to run in.
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 through the step-by-step installation of Apache Tomcat 9 on a Debian 10 (Buster) server.
- A server running one of the following operating systems: Debian 10.
- 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 10
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt-get
commands in the terminal:
apt update apt upgrade
Step 2. Installing Java.
Tomcat 9.0 requires Java SE 8 or later to be installed on the server. Run the following command to install the OpenJDK package:
sudo apt install default-jdk
Verify installed Java version:
java -version
Step 3. Installing Apache Tomcat on Debian 10.
For best practice, Tomcat should never be run as a privileged user (root). We recommend you create a separate system user which will run the Tomcat server. Therefore, issue the following command:
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat
The first thing to do is to go to Apache Tomcat’s download page and download the latest stable version of Apache Tomcat, At the moment of writing this article it is version 9.0.27:
cd /tmp wget https://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz tar -xf apache-tomcat-9.0.27.tar.gz sudo mv apache-tomcat-9.0.27 /opt/tomcat/
Change the ownership of the extracted directory:
sudo chown -R tomcat: /opt/tomcat
Make the scripts inside the bin directory executable:
sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'
Let’s create a systemd
init file so you can start/restart/stop Tomcat:
sudo nano /etc/systemd/system/tomcat.service
[Unit] Description=Tomcat 9.0 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" 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
Notify systemd
that a new unit file exists and starts the Tomcat service by typing:
sudo systemctl daemon-reload sudo systemctl start tomcat
Step 4. Configuring Firewall for Tomcat.
You may need to allow Tomcat server requests in the firewall so that we can access the application from the external network:
sudo ufw allow 8080
Step 5. Test the Installation
Finally, open apache tomcat from your browser, go to your IP or domain with the 8080 port (because Tomcat will always run on the 8080 port) as an example: your-domain.com:8080, replace your-domain.com with your IP or domain.
http://your-ip-address:8080
Congratulations! You have successfully installed Tomcat. Thanks for using this tutorial for installing Apache Tomcat on Ubuntu Debian 10 Buster system. For additional help or useful information, we recommend you check the official Apache Tomcat website.