🔧

Tomcat

1 notes  •  Tools & Utilities

Install Apache Tomcat 8.5 on Ubuntu 18.04

Apache Tomcat is an open-source Java Servlet and JSP container. This guide installs Tomcat 8.5 on Ubuntu 18.04 with OpenJDK and configures it as a systemd service.

Prerequisites

  • Ubuntu 18.04 or 16.04 with sudo access
  • Port 8080 open in the firewall

Steps

# Install OpenJDK
sudo apt update
sudo apt install default-jdk -y
java -version

# Create Tomcat system user
sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat

# Download Tomcat 8.5
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.87/bin/apache-tomcat-8.5.87.tar.gz
sudo tar xzf apache-tomcat-8.5.87.tar.gz -C /opt/tomcat --strip-components=1
sudo chown -R tomcat: /opt/tomcat
sudo chmod +x /opt/tomcat/bin/*.sh

# Create systemd service
sudo nano /etc/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat 8.5
After=network.target

[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="CATALINA_HOME=/opt/tomcat"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat

Verify

sudo systemctl status tomcat

Open http://your-server-ip:8080 — you should see the Tomcat default page.

Notes

  • To access the Tomcat Manager, configure users in /opt/tomcat/conf/tomcat-users.xml.
  • For production, place Nginx in front of Tomcat and proxy port 8080 to port 80/443.
  • These instructions also apply to Ubuntu 16.04 and Linux Mint.