Lab Setup & Configuration

Topics

Installation

Apache Tomcat depends on Java, so the Java JDK must be installed on your server. Use the following command to install it:

sudo apt install openjdk-21-jdk

Create a new user named tomcat with the following command:

sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat

Download the Tomcat tar.gz file from the official website.

Download the latest version to the Ubuntu machine and extract the files:

wget https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.0/bin/apache-tomcat-11.0.0.tar.gz
tar -xvf apache-tomcat-11.0.0.tar.gz

Move the extracted folder to the /opt/tomcat directory, assign ownership to the tomcat user, and set execution permissions for the binary files:

mv apache-tomcat-11.0.0/* /opt/tomcat
chown -R tomcat: /opt/tomcat
sh -c 'chmod +x /opt/tomcat/bin/*.sh'

Create a tomcat.service file in the /etc/systemd/system/ directory with the following content:

Reload the systemd daemon to apply the changes:

Enable the Tomcat service to start automatically on reboot:

Check the Tomcat server status:


Configuration

Once installation is complete, configure the Tomcat server.

To set an admin user password, modify the tomcat-users.xml file:

If neovim is not installed, install it using:

Add the following lines before the closing </tomcat-users> tag:

To enable remote access for the Tomcat Manager, edit the context.xml file in both the manager and host-manager directories:

Remove the following line from both files:

Restart the Tomcat service:

Verify that the Tomcat server is running on port 8080.

Last updated