May 9, 2025 - 18:02
Installing Apache Tomcat Server on Ubuntu Image
Server Management

Installing Apache Tomcat Server on Ubuntu

Comments
Apache Tomcat is a popular open-source application server used to run Java Servlet and JSP (JavaServer Pages) applications. In this guide, I will show you how to install Apache Tomcat 10 step-by-step on Ubuntu 22.04.

1. Update the System

First, let’s update the package manager:
BASH
sudo apt update && sudo apt upgrade -y
This step installs the latest packages and security patches on your system.

2. Install Java

Apache Tomcat requires Java, so you need to install either OpenJDK or Oracle JDK. In this example, I’ll install OpenJDK. To install OpenJDK 11 or 17, run the following command:
BASH
sudo apt install openjdk-11-jdk -y
To verify the installed Java version:
BASH
java -version
If Java is not installed, you can also install OpenJDK 17 with:
BASH
sudo apt install openjdk-17-jdk -y

3. Create the Tomcat User

For security reasons, it's better to run Tomcat under a dedicated user account. Let's create a new user called tomcat:
BASH
sudo useradd -m -U -d /opt/tomcat -s /bin/false tomcat

4. Download Apache Tomcat

Check and download the latest version of Tomcat from the official Apache Tomcat site:
BASH
cd /tmp
wget https://downloads.apache.org/tomcat/tomcat-10/v10.1.39/bin/apache-tomcat-10.1.39.tar.gz
Extract the downloaded archive into the /opt/tomcat directory:
BASH
sudo mkdir -p /opt/tomcat
sudo tar -xvzf apache-tomcat-10.1.39.tar.gz -C /opt/tomcat --strip-components=1
Set the correct permissions for the Tomcat directory:
BASH
sudo chown -R tomcat:tomcat /opt/tomcat
sudo chmod -R 755 /opt/tomcat

5. Start the Tomcat Service

To run Tomcat as a system service, follow these steps:
  1. Create the service file:
BASH
sudo nano /etc/systemd/system/tomcat.service
  1. Add the following content to the file:
INI
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking
User=tomcat
Group=tomcat
Environment='JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64'
Environment='CATALINA_PID=/opt/tomcat/temp/tomcat.pid'
Environment='CATALINA_HOME=/opt/tomcat'
Environment='CATALINA_BASE=/opt/tomcat'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=always

[Install]
WantedBy=multi-user.target
Save and close the file (press CTRL+X, then Y and ENTER).
  1. Enable and start the Tomcat service:
BASH
sudo systemctl daemon-reload
sudo systemctl enable tomcat
sudo systemctl start tomcat
Check that Tomcat is running:
BASH
sudo systemctl status tomcat
If you see “active (running)”, Tomcat is running successfully.

6. Accessing the Tomcat Web Interface

By default, Tomcat runs on port 8080. To access the interface, open your browser and visit:
PLAINTEXT
http://localhost:8080
If you're using a remote server, replace localhost with your server’s IP address or domain name:
PLAINTEXT
http://your-server-ip:8080
If you're having trouble accessing the interface, you may need to open port 8080 in your firewall:
BASH
sudo ufw allow 8080/tcp

7. Enabling the Tomcat Admin Panel

To access the Tomcat Manager interface, you need to define a user. Edit the following file:
BASH
sudo nano /opt/tomcat/conf/tomcat-users.xml
Add the following lines inside the file:
XML
<role rolename='manager-gui'/>
<user username='admin' password='admin123' roles='manager-gui'/>
Save the changes and restart Tomcat:
BASH
sudo systemctl restart tomcat
Then, open your browser and navigate to http://localhost:8080/manager/html to log in.

8. Enabling Tomcat to Start Automatically

To ensure Tomcat starts automatically every time your server boots up, run the following command:
BASH
sudo systemctl enable tomcat

Now Apache Tomcat is successfully running on your Ubuntu server. You can now deploy your web applications and configure Tomcat settings via the manager panel. If you encounter any issues, you can check the Tomcat logs using:
BASH
sudo journalctl -u tomcat --no-pager | tail -n 50

Related Articles

Comments ()

No comments yet. Be the first to comment!

Leave a Comment