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 an Ubuntu 16.04/18.04 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.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

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

You can check your Java version by issuing the command below:

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 9.0.22.

sudo wget https://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.22/bin/apache-tomcat-9.0.22.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.22.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.


<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:

Description=Tomcat servlet container




Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"



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 as shown below: cloudwaferlabs.com.ng:8080