Apache Tomcat® software is an open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. The Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket specifications are developed under the Java Community Process.
In this guide, we will install Apache Tomcat on a Debian 9 Server.
Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.
Updating System Packages
It is always recommended that you update the system to the latest packages before beginning any major installations. This is done with the command below:
sudo apt-get update && sudo apt-get upgrade
Step 1: Install OpenJDK
One of the core requirements needed by Tomcat is Java JDK. Hence we are going to install this using the APT tool from Ubuntu's repository. Issue the command below to install OpenJDK:
sudo apt install default-jdk
After installation, issue the command below to verify our installation and check the Java version:
Step 2: Create Tomcat User and Service Account
For security purposes, we are going to run Tomcat as it own user without root privileges by creating a new user and group that will run the Tomcat service. Issue the commands below to do this: To do that, run the commands below
sudo groupadd tomcat sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Step 3: Download Tomcat Packages
We can now download the official Tomcat Package from the Tomcat 9 Software Download webpage At the time of writing this guide the latest version of the 9 series is
cd /tmp sudo wget http://mirror.vorboss.net/apache/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz
Next, create a new Tomcat directory;
/opt/tomcat which is where we are going to extract the downloaded Tomcat package.
sudo mkdir /opt/tomcat sudo tar xzvf apache-tomcat-9.0.27.tar.gz -C /opt/tomcat --strip-components=1
Next, grant the
tomcat user control of the entire directory and change the permissions of all the scripts in the
bin location executable using the commands below:
sudo chown -R tomcat: /opt/tomcat sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh'
Step 4: Configure Tomcat Service
After extracting, issue the commands below to make changes to the Tomcat configuration file for the default user:
sudo nano /opt/tomcat/conf/tomcat-users.xml
We are going to create an account for the user as shown below replacing
admin123 with a more secure password.
</tomcat-users> <role rolename="manager-gui"/> <role rolename="admin-gui"/> <user username="admin" password="admin123" roles="manager-gui,admin-gui"/>
Next, we are going to create a server account for Tomcat by issuing the command below:
sudo nano /etc/systemd/system/tomcat.service
Enter the following:
[Unit] Description=Tomcat 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" 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
Ensure to save before you exit.
Next, reload systemd profiles and enable tomcat to start on boot using the commands below:
sudo systemctl daemon-reload sudo systemctl start tomcat.service sudo systemctl enable tomcat.service
You can check the status of the Tomcat service using the command below:
sudo systemctl status tomcat.service
You can now visit your domain or IP address on port 8080 on port 8080 as shown below: