DevOps Classroom notes 18/Jun/2026

Tomcat Installation on Ubuntu

Reference

Install Tomcat

# Create Tomcat user and provide access to /opt/tomcat
sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat

# Update package index
sudo apt update

# Install Java 17
sudo apt install openjdk-17-jdk -y

# Verify Java installation
java --version

# Move to temporary directory
cd /tmp

# Download Tomcat package
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.55/bin/apache-tomcat-10.1.55.tar.gz

# Extract Tomcat into /opt/tomcat
sudo tar xzvf apache-tomcat-10.1.55.tar.gz \
  -C /opt/tomcat \
  --strip-components=1

# Set ownership and permissions
sudo chown -R tomcat:tomcat /opt/tomcat
sudo chmod -R u+x /opt/tomcat/bin

Configure Tomcat Users

Edit the Tomcat users configuration file:

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

Add the following content inside the <tomcat-users> section:

<role rolename="manager-gui" />
<user username="manager" password="manager_password" roles="manager-gui" />

<role rolename="admin-gui" />
<user username="admin" password="admin_password" roles="manager-gui,admin-gui" />

Allow Remote Access to Tomcat Manager

Edit the Manager application context file:

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

Replace/comment the RemoteAddrValve section as shown below:

<Context antiResourceLocking="false" privileged="true">
    <CookieProcessor
        className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
        sameSiteCookies="strict" />

    <!--
    <Valve
        className="org.apache.catalina.valves.RemoteAddrValve"
        allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
    -->
</Context>

Repeat the same change for:

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

Create Systemd Service

List installed Java versions:

sudo update-java-alternatives -l

Create a Tomcat systemd service file:

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

Add the following content:

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

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"

Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Start and Enable Tomcat

# Reload systemd configuration
sudo systemctl daemon-reload

# Start Tomcat
sudo systemctl start tomcat

# Enable Tomcat at boot
sudo systemctl enable tomcat

# Check service status
sudo systemctl status tomcat

Verify Installation

Open the following URL in your browser:

http://<SERVER_IP>:8080

Tomcat Manager:

http://<SERVER_IP>:8080/manager/html

Tomcat Host Manager:

http://<SERVER_IP>:8080/host-manager/html

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%