Steps to Install Tomcat on Ubuntu 18.04

install-Tomcat-on-Ubuntu-18

Tomcat usually know as Apache Tomcat is one of the most widely adopted application and web servers in the world today. It is the most useable servlet containers available. So before we go through the steps to install Tomcat on Ubuntu 18.04, let’s see the advantages.

Advantages of Tomcat

You get a lot of benefits using Tomcat

Tomcat is an open-source application and it’s free

It is useful for its easy and quickness to run your applications in Ubuntu, as it provides you quick loading and helps run a server more efficiently

It comes with a suite of comprehensive, built-in customization choices which helps you to work flexibly

With its extra level of security and stability, the rest of the server keeps working when any issue arises.

Install Tomcat on Ubuntu 18.04

We at actsupport help our clients in Server Administration, where we configure, monitor, and maintain the entire server health from any disruption.

You can use the below steps for other Ubuntu-based distributions, so let’s get started.

Set up your server with a non-root user that has sudo privileges to install packages on your Ubuntu system.

Step 1: Install Java

Before you install Tomcat you need to install Java, this is simple and quick; you can install OpenJDK as it is the default Java development in Ubuntu 18.04.

You can update the package index using the command:

sudo apt update

You can now install the OpenJDK package by running:

sudo apt install default–jdk

Step 2: Create Tomcat User

Note: You should not run Tomcat under the root user due to security reasons.

Run the service by creating a new tomcat group

sudo groupadd tomcat

Now you can create user members of the Tomcat group with a home directory opt/tomcat to run the Tomcat service:

sudo useradd -s /bin/false -g tomcat
-d /opt/tomcat tomcat

Step 3: Install Tomcat on Ubuntu

You will have to configure it manually, you can simply download the latest binary release from the Tomcat 9 downloads page.

Make sure you check the download page for a new version and if you have a new version you can copy the link to the Core tar.gz file, this will be under the Binary Distributions section.

Now download the Tomcat archive that is in the /tmp directory using the below wget command:

wget
http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz
-P /tmp

After downloading you have to extract the Tomcat archive and move it to the /opt/tomcat directory. You won’t require this after extracting the Tomcat contents:

cd /tmp

You can use the below curl command to download the copied link

curl -O
https://www-us.apache.org/dist/tomcat/tomcat-9/v9.0.17/bin/apache-tomcat-9.0.17.tar.gz

Step 4: Update Tomcat Permission

Once you finished the installation of Tomcat on Ubuntu, then you need to setup execute privileges access to Tomcat user over the installation directory.  Follow the steps below:

1.       Move the directory where the Tomcat Installation is located:

sudo mkdir /opt/tomcat 
cd /opt/tomcat

2.   Now, Grant the group ownership over the installation of a directory to the tomcat group with chgrp command

sudo chgrp –R tomcat /opt/tomcat

3.        Give access to the conf directory and its content and change directory permission to grant execute access

sudo chmod –R g+r conf
sudo chmod g+x conf                   

4.        Finally, make the Tomcat user ownership of webapps, work, temp, and logs directories by using this command:

sudo chown –R tomcat webapps/ work temp/ logs

Step 5: Create System Unit File                       

Since you are going to access Tomcat as a service, you need to create a system service file.

•          To configure the file, you need to set the common path as “JAVA_HOME” the exact location where Java is installed. Check the location by running this command

sudo update-java-alternatives -l

•          Open tomcat.service and create a new file in the /etc/systemd/system/

sudo nano /etc/systemd/system/tomcat.service

•          Once the file is opened, Paste the following configuration

[Unit]
Description=Apache
Tomcat Web Application Container
After=network.target

[Service]

Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64
Environment=CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment=’CATALINA_OPTS=-Xms512Mm–Xmx1024M –server –XX:+UserParallelGC’
Environment=’JAVA_OPTS=-Djava.awt.headless=true
Djava.security.egd=file:/dev/./urandom’
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat
UMast=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

When completed, Save and exit the file.

To reload the system daemon

sudo systemctl daemon-reload

Now, follow the command to start the Tomcat Service

sudo systemctl start tomcat

Check the status of Apache Tomcat Service

sudo systemctl status tomcat 

Step 6: Adjust the Firewall

If you are using a firewall to protect your server, then you will be unable to access the Tomcat Interface. It is necessary to adjust the firewall to get the request for the service.

Uses Tomcat port 8080 to allow traffic through it with the below command

sudo ufw allow 8080/tcp            

If the port is open, you can access the Apache Tomcat splash page by entering the following command in the browser

http://server_ip:8080 or http://localhost:8080

Step 7: Configure Web Management Interface

Now, you want to create a user who can use the web management interface for that;

•          Open the user’s file

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

•          Now, determine the user who can access the files and add username and password:

tomcat-users.xml — Admin 

User
<tomcat-users. . .>
<tomcat-users. . .>
<userusername="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>

Note: Make sure to replace the strong password with your preference.

•          Save and exit the file.

For the Manager app, type:

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

For the Host Manager app, type:

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

To restart the Tomcat service:

sudo systemctl restart tomcat

Step 8: Access the web Interface

To access the web management interface you already have a user. Now you can access the interface by adding your server’s domain name or IP address followed by port 8080 in your browser

http://server_domain_or_IP:8080

Let’s check the Manager App, accessible through the below link

http://server_domain_or_IP:8080/manager/html

Also, check that you entered the account credentials to the tomcat-users.xml file.

Our Java applications are managed by the Web Application manager. You can also Begin, Stop, reload, Deploy, and Undeploy apps. It will also provide data about your server at the bottom of the page.

Now let’s check at the Host Manager, accessible through the below link

http://server_domain_or_IP:8080/host-manager/html/

From the Virtual Host Manager page, you can also add new virtual hosts to serve your application form’s guidelines.

Wrapping Up

Wasn’t that easy to install Tomcat 9 on your Ubuntu 18.04 system and it would be best if you could encrypt your connections with SSL, as the data’s, passwords, and other sensitive data or information can be modified by other parties?

If you find any trouble during the configuration you can get our assistance.

Follow us on Facebook, Twitter, LinkedIn

Subscribe to get free blog content to your Inbox
Loading

Written by actsupp-r0cks