How to Install Apache Tomcat 9 on Ubuntu 18.04

How to Install Apache Tomcat 9 on Ubuntu 18.04

Apache Tomcat is a web server application for running Java Servlet, Java Server Pages, Java Expression Language, and Java WebSocket.

Install Apache Tomcat

Before installing Apache Tomcat, first update Ubuntu and install default-jdk.

Creating groups and users tomcat.

Download Apache Tomcat 9

Extract the apache-tomcat-*.tar.gz file, copy it to the tomcat folder, and change the owner and permissions.

Check where the Java-JDK folder is to be included in the tomcat service configuration. The results are in /usr/lib/jvm/java-1.11.0-openjdk-amd64.

Creating a tomcat service configuration file.

The contents of the tomcat service configuration file.

Reload service configuration, run and activate Tomcat service. Service status must be active (running).

Apache Tomcat service
Apache Tomcat service

Browse http: // ip-server: 8080 to test whether Apache Tomcat is working properly.

Apache Tomcat Web Management Interface
Apache Tomcat Web Management Interface

Configuring Tomcat Web Management Interface

Configure users who access the web management interface.

Enter the user configuration below between the tomcat-users tags. This user can access manager-gui and admin-gui.

Tomcat users configuration
Tomcat users configuration

By default, Tomcat restricts access to Manager and Host Manager, it can only be accessed from localhost or 127.0.0.1. Because the Tomcat web management interface is accessed remotely, the configuration of access restrictions must be disabled or write the Public IP that we use to access the Tomcat web management interface.

Configuration file for Manager.

Configuration file for Host Manager.

Mark as a comment on the configuration Valve className =” org.apache.catalina.valves.RemoteAddrValve.

Apache Tomcat Manager/Host Manager remote configuration
Apache Tomcat Manager/Host Manager remote configuration

Restart tomcat service.

Browse http://ip-server:8080.

Test click menu ‘Server Status’, ‘Manager App’, and ‘Host Manager’, must be accessible.

Apache Tomcat server status
Apache Tomcat server status
Apache Tomcat manager app
Apache Tomcat manager app
Apache Tomcat host app
Apache Tomcat host app

Running a JSP File

Next test run JSP file.

The Document Root folder is located at /opt/tomcat/webapps/ROOT.

Displays date with JSP.

Change permissions and ownership.

Browse http://ip-server:8080/date.jsp

Date JSP
Date JSP

Redirect Port

By default, the Tomcat web server runs on port 8080. So that Tomcat can be accessed through port 80, we can do this by adding rules in iptables.

This rule will forward or redirect requests for port 80 to 8080 (HTTP) and 443 to 8443 (HTTPS) access.

Browse for http://ip-server, if it can be accessed via port 80.

Apache Tomcat via port 80
Apache Tomcat via port 80

Good luck 🙂

Leave a Reply