Install Java and Tomcat on Ubuntu 22.04

READ: https://tecadmin.net/how-to-install-tomcat-on-ubuntu-22-04/
ALSO READ: https://myprojects.advchaweb.com/index.php/2021/09/27/install-tomcat-on-ubuntu-20-04/

INSTALL OPENJDK 11

CHECK JAVA VERSION

CREATE A TOMCAT USER

DOWNLOAD TOMCAT 10
AT THE TIME, THE LATEST STABLE VERSION IS 10.1.19. DOWNLOAD THE BINARY (https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.19/bin/apache-tomcat-10.1.19.tar.gz)

EXTRACT IT TO /opt/tomcat DIR

SET THE PERMISSION
First, we’ll change the directory ownership to tomcat.

Next, make all scripts within the bin directory executable.

Create Tomcat Application Accounts
Now, configure your tomcat with user accounts to secure access of admin/manager pages. To do this, edit conf/tomcat-users.xml file in your editor and paste the following code inside <tomcat-users> </tomcat-users> tags. We recommend changing the password in the below configuration with high secured password.

ADD THE ROLES

Allow Remote Hosts to Access Tomcat
The default Tomcat manager and host-manager applications are accessible for localhost only. To allow access to these pages from the remote system, you need to modify the following configuration files.

You can either allow a specific remote system or allow all. Edit the context.xml file for manager and host manager application:

Comment out the section added for IP address restriction to allow connections from anywhere.

Similarly edit context.xml for host manager application in text editor:

Create a Systemd Service File
We’ll now create a systemd service file to manage the Tomcat service. Open a new service file in a text editor:

Paste in the following configuration:

Start and Enable Tomcat
After creating the service file, reload the systemd daemon to read the new file:

Next, start the Tomcat service with:

CHECK Tomcat service status

If everything went well, enable Tomcat to start on boot:

Open the Firewall
You also need to check if the firewall is not blocking the incoming connections to Tomcat’s port (default is 8080). This depends on what firewall you are using:

For UFW (Uncomplicated Firewall) in Ubuntu:

Test the Installation
The default Tomcat server runs on port 8080. As you have configured Tomcat on your system, you can access web interface from your system. You can access tomcat interfaces by entering your server’s IP address or a domain name pointed to that server, followed by port 8080 in your browser:

http://localhost:8080/

Tomcat Manager App is a web application packaged with the Tomcat server application. The Manager interface provides us with the basic functionality we need to manage our deployed web applications.

Click the Manager App button home page or directly type /manager in the browser URL of the main Tomcat server to access it.
http://localhost:8080/manager/html
user: admin
pass: Admin@123

TOMCAT LOG
THE DEFAULT LOG FILE IS IN /opt/tomcat/apache-tomcat-10.1.19/logs/ DIR!
THE LOG FILE IS /opt/tomcat/apache-tomcat-10.1.19/logs/catalina.out
To change the default location of the log file, edit the startup.sh file and locate the entry: