Apache Tomcat
Apache Tomcat is an open-source servlet container that runs Java web applications. It implements the Jakarta Servlet, JSP, and WebSocket specifications and serves WAR files over HTTP, making it a standard choice for hosting Java backends.
Software included
Section titled “Software included”| Component | Version |
|---|---|
| Apache Tomcat | 11.0.24 |
| OpenJDK | 21 (JRE) |
| Ubuntu | 24.04 LTS |
Getting started
Section titled “Getting started”1. Connect to your VM
Section titled “1. Connect to your VM”ssh ubuntu@<your-vm-ip>2. Wait for first-boot configuration
Section titled “2. Wait for first-boot configuration”On the first boot, a setup script creates the Manager and Host Manager administrator, starts Tomcat, and writes the credentials to disk. This takes about a minute. Track progress:
journalctl -u tomcat-first-boot.service -fThe login message (MOTD) confirms when Tomcat is ready.
3. Verify Apache Tomcat is running
Section titled “3. Verify Apache Tomcat is running”systemctl status tomcatcurl -I http://localhost:80804. Access Apache Tomcat
Section titled “4. Access Apache Tomcat”Open a browser and navigate to:
http://<your-vm-ip>:8080Retrieve the Manager credentials:
sudo cat /root/.credentials/tomcat.txt| Field | Value |
|---|---|
| Username | admin |
| Password | From /root/.credentials/tomcat.txt |
The Manager and Host Manager apps accept localhost connections only. Use the SSH tunnel shown in the credentials file to access them.
Managing Apache Tomcat
Section titled “Managing Apache Tomcat”# Check service statussystemctl status tomcat
# Restartsudo systemctl restart tomcat
# View logssudo journalctl -u tomcat -f| Path | Purpose |
|---|---|
/opt/tomcat/conf/tomcat-users.xml | Manager users and roles |
/opt/tomcat/webapps/ | Deployed applications and WAR files |
/opt/tomcat/logs/ | Tomcat logs |
Security
Section titled “Security”Port 8080 is accessible on the VM’s network interface. UFW is enabled and allows SSH (port 22) and Tomcat (port 8080) by default. The Manager and Host Manager apps remain restricted to localhost by Tomcat.
To restrict Tomcat to a specific IP:
sudo ufw delete allow 8080/tcpsudo ufw allow from <trusted-ip> to any port 8080To access Tomcat without exposing port 8080, use an SSH tunnel:
# Run this on your local machinessh -L 8080:localhost:8080 ubuntu@<your-vm-ip>
# Then open in your browserhttp://localhost:8080http://localhost:8080/manager/htmlFor production use, place Tomcat behind a reverse proxy such as Nginx or HAProxy so you can serve it on port 443 with a TLS certificate.