---
title: How to Install and Configure Apache Tomcat on Linux – Almalinux
description: "Here’s a step-by-step guide to installing and configuring Apache Tomcat on AlmaLinux. ### 1. Prerequisites: Installing Java Apache Tomcat requires Java to run, so start by installing OpenJDK on your AlmaLinux system. #### Update System Packages Update the package index…"
url: "https://truehost.com/support/knowledge-base/how-to-install-and-configure-apache-tomcat-on-linux-almalinux/"
updated: "2024-11-01"
category: Cloud servers in Kenya
---

# How to Install and Configure Apache Tomcat on Linux – Almalinux

Here’s a step-by-step guide to installing and configuring Apache Tomcat on AlmaLinux.

### 1. Prerequisites: Installing Java

Apache Tomcat requires Java to run, so start by installing OpenJDK on your AlmaLinux system.

#### Update System Packages

Update the package index to ensure you have the latest version of each package:

```
sudo dnf update -y
```

#### Install Java

Use the `dnf` package manager to install the default Java Development Kit (JDK):

```
sudo dnf install -y java-11-openjdk
```

Once installed, verify the Java version to ensure it’s set up correctly:

```
java -version
```

### 2. Creating a Tomcat User

Running Tomcat as the root user isn’t secure, so create a dedicated user for Tomcat with restricted permissions.

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

This creates a system user named `tomcat`, with its home directory at `/opt/tomcat`, which we’ll use as the Tomcat installation directory.

### 3. Downloading and Extracting Tomcat

Visit the [Apache Tomcat download page](https://tomcat.apache.org/download-90.cgi) to get the latest version. Here, we’ll use version 9.0.34 as an example.

#### Download Tomcat

Download the tarball using `wget`:

```
wget -c https://downloads.apache.org/tomcat/tomcat-9/v9.0.34/bin/apache-tomcat-9.0.34.tar.gz
```

#### Extract the Tomcat Archive

After downloading, extract the archive to the `/opt/tomcat` directory:

```
sudo mkdir /opt/tomcat
sudo tar xf apache-tomcat-9.0.34.tar.gz -C /opt/tomcat
```

To make future updates easier, create a symbolic link named `latest` that points to the Tomcat installation directory:

```
sudo ln -s /opt/tomcat/apache-tomcat-9.0.34 /opt/tomcat/latest
```

#### Set Permissions

Ensure the `tomcat` user has full ownership of the Tomcat directory:

```
sudo chown -R tomcat: /opt/tomcatsudo chmod +x /opt/tomcat/latest/bin/*.sh
```

### 4. Configuring Tomcat as a Systemd Service

To run Tomcat as a service on AlmaLinux, create a systemd unit file.

#### Create a Unit File

Create a new file for the Tomcat service:

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

Add the following content, adjusting the `JAVA_HOME` path if needed:

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

[Service]
Type=forking

Environment="JAVA_HOME=/usr/lib/jvm/java-11-openjdk"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"

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

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
```

#### Reload the Systemd Daemon

Reload systemd to recognize the new Tomcat service file:

```
sudo systemctl daemon-reload
```

#### Start and Enable the Tomcat Service

Now, start the Tomcat service and enable it to start on boot:

```
sudo systemctl start tomcat
sudo systemctl enable tomcat
```

Verify the Tomcat Service Status

Check the status to make sure Tomcat is running:

```
sudo systemctl status tomcat
```

5. Configuring the Firewall

If you have a firewall enabled, allow access to Tomcat’s default port, 8080:

```
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
```

6. Verifying the Tomcat Installation

To verify that Tomcat is successfully installed, open a browser and go to the following URL, replacing `<YourIPAddress>` with the server’s IP address:

```
http://:your_ip_addresss:8080
```

If everything was configured correctly, you should see the Tomcat default welcome page.

### Optional: Securing the Tomcat Manager and Host Manager

1. **Enable the Tomcat Manager Application** by editing the `tomcat-users.xml` file:

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

2**. Add Roles and a User**: Add a user with `manager-gui` and `admin-gui` roles:

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

3. **Restart Tomcat** to apply changes:

```
sudo systemctl restart tomcat
```

You can now log in to the Manager and Host Manager applications using the configured credentials.

### Author's Final Word

This guide covers the installation and basic configuration of Apache Tomcat on AlmaLinux. You’re now ready to deploy and manage Java web applications on Tomcat. Remember to keep Tomcat up to date for security and performance improvements.
