How to install Tomcat on Ubuntu 18.04

Tomcat, often called Apache Tomcat, is one of the most popular applications designed to run a Java servlet and render web servers with Java page encoding. It is an open source application released by the Apache Software Foundation. It is the favorite of many developers! Because of this, in this tutorial, we will show you how to install Tomcat on Ubuntu 18.04 and how to configure it to use it on your !

Tomcat generates JSP files (server-generated web pages, similar to PHP and ASP files) into Java code, further compiling the files .class by the server and executed by the Java virtual machine. Today Tomcat is definitely one of the most widely used servlet containers available.

Benefits of Apache Tomcat

  • Tomcat is a fast and easy way to run your applications on the . It provides fast loading and helps run a server more efficiently.
  • Tomcat contains a set of comprehensive built-in customization options that allow its users to work flexibly.
  • Thanks to its stability, even having problems in Tomcat, it is not an inconvenience for the rest of the server to work.
  • Tomcat is a free open source application. It offers great customization through code access.
  • Tomcat offers its users an additional level of security.

How to install Tomcat on Ubuntu

This tutorial will teach you how to install Tomcat 9 on Ubuntu 18.04 and how to configure it for use. The same tutorial applies to Ubuntu 16.04 and other Ubuntu-based versions.

Before starting the guide, it is important that you have a non-root user with sudo privileges configured on your server. Remember to access your server with . Consult our if you have problems.

Step 1: Install Java

Before installing Tomcat on Ubuntu, you will need to install Java to run the Java web application code. OpenJDK is the default Java development in Ubuntu 18.04. Installing Java is simple and fast. Simply use the following commands:

See also  How to Fix HTTP Error When Loading Images in WordPress

sudo apt update

Install the package by running:

sudo apt install default-jdk

Now that the JDK is installed on your system, you can create the tomcat user by following the next step.

Step 2 — Create a Tomcat User

For security, you should not use Tomcat without a single user. This will make it easy to install Tomcat on Ubuntu. Create a new tomcat group that will run the service:

sudo groupadd tomcat

Now the next step is to create a new tomcat user. Add users to the Tomcat group with the opt/tomcat home directory to run the Tomcat service:

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

Step 3: Install Tomcat on Ubuntu

The best way to install Tomcat 9 on Ubuntu is by downloading the latest binary version of Tomcat 9 and configuring it manually. If the version is not 9.0.17 or the latest version, please download the latest stable version. Simply copy the link to the core file in the Binary Distributions section.

Now, change to the directory /tmp on your server to download items you won’t need after extracting the content from Tomcat:

cd /tmp

To download from the copied link (from the Tomcat website), use the following:

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 permissions

Now that you have finished installing Tomcat on Ubuntu, you need to configure the Tomcat user to have full access to the Tomcat installation. This user must have access to the directory. Use the following commands:

sudo mkdir /opt/tomcat cd /opt/tomcat sudo tar xzvf /tmp/apache-tomcat-9.0.*tar.gz -C /opt/tomcat –strip-components=1

Now, give the Tomcat group ownership of the entire installation directory with the :

sudo chgrp -R tomcat /opt/tomcat

Next, you need to grant the Tomcat user access to the conf directory to view its contents and run access to the directory itself:

See also  Privacy Policy

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

Make the Tomcat user the owner of the apps, work, temp, and logs directories:

sudo chown -R tomcat webapps/work/temp/logs/

Step 5: Create a systemd unit file

You will need to create a new unit file to run Tomcat as a service. Open your text editor and create a file name tomcat.service in /etc/systemd/system/:

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

Next, copy and paste the following configuration:

Description=Apache Tomcat Web Application Container After=network.target Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre Environment=CATALINA_PID=/opt/tomcat/temp/tomcat. pid Environment=CATALINA_Home=/opt/tomcat Environment=CATALINA_BASE=/opt/tomcat Environment=’CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC’ Environment=’JAVA_OPTS.awt.headless=true -Djava.security.egd =file:/dev/v/urandom’ ExecStart=/opt/tomcat/bin/startup.sh ExecStop=/opt/tomcat/bin/shutdown.sh User=tomcat Group=tomcat UMask=0007 RestartSec=10 Restart=always WantedBy =multi-user.target

Save and close the file after finishing with the above commands.

Next, notify the system that you have created a new file by issuing the following command at the command line:

sudo systemctl daemon-reload

The following commands will allow you to run the Tomcat service:

cd /opt/tomcat/bin sudo ./startup.sh run

Step 6: Adjust the Firewall

Tuning the firewall is essential for requests to reach the service. Tomcat uses port 8080 to accept conventional requests. Allow traffic to that port using :

sudo ufw allow 8080

To access the home page go to your domain or IP address followed by: 8080 in a web browser – http://IP:8080

Step 7: Configure the Tomcat web management interface

Use the following command to add a login to your Tomcat user and edit the file tomcat-users.xml:

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

Now define the user who can access the files and add the username and passwords:

tomcat-users.xml — Admin User

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

And, if you want to restart the Tomcat service and see the effects use the following command:

sudo systemctl restart tomcat

Step 8: Access the online interface

Now that you have a user, you can access the web administration interface in a browser. Once again, you can access the interface by providing the domain name or IP address of your server, followed by port 8080 in your browser: http://domain_or_IP:8080.

See also  The best pages to sell online: 10 marketplaces to sell products or manage a business

Take a look at the application manager, accessible via the link: http://domain_or_IP:8080/manager/html.

Make sure you have entered the account credentials on file tomcat-users.xml.

The Web Application Manager can be used to manage your Java applications. You can start, stop, reload, deploy and undeploy all apps.

Lastly, provide information about your server at the bottom of the page.

Now take a look at host administratoraccessible through http://domain_or_IP:8080/host-manager/html/

From the page Virtual HostManageryou can also add new virtual hosts that follow the guidelines on their request form.

Summary

Ubuntu supports Tomcat 6 and the latest version Tomcat 9, which includes new features to allow users to work freely in the application.

With this tutorial, the Tomcat installation is functional but not encrypted, so information, passwords, and other sensitive data can be seen or changed by other parts of the web browser. The only way to solve this problem is to encrypt your connections with .

As you can see, it is not complicated at all to install Tomcat on Ubuntu, you only need a couple of minutes and this step-by-step guide that details the entire process. We hope it has been helpful!

Deyi is a digital marketing enthusiast, with a background in web design, content creation, copywriting, and SEO. She is part of ‘s SEO & Localization team. In her free time, she likes to develop projects, read a book or watch a good movie.

Loading Facebook Comments ...
Loading Disqus Comments ...