Apache Tomcat or “Tomcat” is a free and open-source Java Servlet container for Java code and applications. It provides a “pure Java” HTTP server environment where Java code can run. Tomcat also implements JavaServer Pages, Java Expression Language, and WebSocket technologies. It supports SSL for securing sensitive data such as authentication.

This guide will teach you how to install Apache Tomcat on an Ubuntu 24.04 server. You will install Apache Tomcat 10 with the Java OpenJDK 21 and then install and configure Nginx as a reverse proxy.

Prerequisites

Before moving on, make sure you have:

  • An Ubuntu 24.04 server.
  • A non-root user with administrator privileges.

Installing Java OpenJDK

Before installing Apache Tomcat, you need to ensure that Java is installed. The latest Apache Tomcat 10 required at least Java 11 or later. In this section, you will install Java OpenJDK 21 from the official Ubuntu repository.

To start, update your Ubuntu package index with the command below.

sudo apt update

<img alt="update repo" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/1-update-repo.png664736b924160.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="190" loading="lazy" src="data:image/svg xml,” width=”706″>

Now install the Java OpenJDK with the following command. On Ubuntu 24.04, the ‘default-jdk’ refers to the OpenJDK 21, which is the LTS version of Java.

sudo apt install default-jdk

Input Y to proceed with the installation.

<img alt="install java" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/2-install-java.png664736b96c963.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="242" loading="lazy" src="data:image/svg xml,” width=”750″>

After the installation is complete, check the Java version using the following command. You should see that Java OpenJDK 21 is installed on your Ubuntu server.

java --version

<img alt="check java" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/3-check-java.png664736b995a70.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="122" loading="lazy" src="data:image/svg xml,” width=”750″>

Installing Apache Tomcat 10

The Apache Tomcat 10 is available by default on the Ubuntu repository on the latest Ubuntu version. This allows you to install Tomcat easily using the APT package manager.

First, check the ‘tomcat10‘ package information with the following command.

sudo apt info tomcat10

The following shows that Apache Tomcat 10.1.16 is available on the Ubuntu ‘universe/java‘ repository.

<img alt="info tomcat10 package" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/4-tomcat10-info.png664736b9e3d36.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="553" loading="lazy" src="data:image/svg xml,” width=”750″>

Now install Apache Tomcat to your Ubuntu system with the command below. With this command, you will also install the Tomcat admin web applications, tools to create users, and examples of Tomcat web applications.

sudo apt install tomcat10 tomcat10-common tomcat10-admin tomcat10-user tomcat10-examples

Input Y to confirm the installation.

<img alt="installing apache tomcat" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/5-install-tomcat10.png664736ba2f16a.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="207" loading="lazy" src="data:image/svg xml,” width=”750″>

The ‘tomcat10’ service will be created when the installation is finished.

Check the ‘tomcat10‘ service status with the following command:

sudo systemctl is-enabled tomcat10

sudo systemctl status tomcat10

You can see below, the ‘tomcat10‘ service is enabled and active(running). The ‘tomcat10‘ service will start automatically at boot.

<img alt="check tomcat service" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/10-check-tomcat10.png664736ba63105.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="269" loading="lazy" src="data:image/svg xml,” width=”750″>

Now run the command below to check the Apache Tomcat port 8080. If Tomcat is running, you will see the Java application uses port 8080.

ss -tulpn

<img alt="check tomcat port" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/11-check-port.png664736baad88e.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="143" loading="lazy" src="data:image/svg xml,” width=”750″>

Lastly, visit http://192.168.5.30:8080/ using your web browser and you will see the Apache Tomcat default index page like the following:

<img alt="tomcat index" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/6-tomcat-index.png664736bb1db76.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="238" loading="lazy" src="data:image/svg xml,” width=”750″>

Setting up Apache Tomcat authentication

In this section, you will set up basic authentication and allow access to the Tomcat host manager and manager. You will enable Tomcat basic authentication by editing the ‘tomcat-users.xml’ file, then allowing access to both Tomcat host-manager and manager through the ‘tomcat10-admin’ package.

Open the Tomcat user configuration ‘/etc/tomcat10/tomcat-users.xml’ using the nano editor.

sudo nano /etc/tomcat10/tomcat-users.xml

Insert the following configuration between the ‘ …. ‘. In this example, you will create Apache Tomcat user ‘admin‘ with the password ‘tomcatadmin‘ and multiple roles including ‘admin-gui’ and ‘manager-gui’.

<!--

user: admin pass: tomcatadmin

-->













When finished, save and exit the file.

Now open the configuration for the Tomcat ‘host-manager‘ and ‘manager‘ with the nano editor command below.

sudo nano /usr/share/tomcat10-admin/host-manager/META-INF/context.xml

sudo nano /usr/share/tomcat10-admin/manager/META-INF/context.xml

Comment on the following configuration by adding ‘. With this, you will allow remote access to the Apache Tomcat ‘host-manager‘ and ‘manager‘.

<!--

<Valve className="org.apache.catalina.valves.RemoteAddrValve"

allow="127.d .d .d |::1|0:0:0:0:0:0:0:1" />

-->

Save and exit the file.

After editing, run the following command to restart the ‘tomcat10’ service and apply the new changes to your Apache Tomcat installation.

sudo systemctl restart tomcat10

Lastly, visit http://192.168.5.30:8080/host-manager/ to access the Apache Tomcat virtual host manager and http://192.168.5.30:8080/manager/ for the Tomcat manager.

Type the user ‘admin‘ and password ‘tomcatadmin‘ when prompted.

<img alt="login to apache tomcat" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/7-login.png664736bb53edf.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="330" loading="lazy" src="data:image/svg xml,” width=”472″>

If authentication is successful, you should get the Apache Tomcat host-manager and manager page like the following:

Apache Tomcat manager.

<img alt="tomcat manager" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/8-web-app-manager.png664736bb897d8.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="444" loading="lazy" src="data:image/svg xml,” width=”750″>

Apache Tomcat host-manager.

<img alt="tomcat manager" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/9-host-manager.png664736bbb0d20.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="429" loading="lazy" src="data:image/svg xml,” width=”750″>

Setting up Nginx as a reverse proxy

In this guide, you will install the Nginx web server and configure it as a reverse proxy for your Apache Tomcat installation. By using a reverse proxy, you can easily access your Tomcat application through your local domain name.

To install the Nginx web server on your Ubuntu, run the following:

sudo apt install nginx -y

<img alt="install nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/12-install-nginx.png664736bbeca2d.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="374" loading="lazy" src="data:image/svg xml,” width=”750″>

When the installation is finished, create a new server block configuration ‘/etc/nginx/sites-available/tomcat10‘ that will be used as a reverse proxy for Apache Tomcat.

sudo nano /etc/nginx/sites-available/tomcat10

Add the configuration below and change your local domain name using the server_name option.

server {

listen 80;

server_name tomcat10.hwdomain.io;

access_log /var/log/nginx/tomcat-access.log;

error_log /var/log/nginx/tomcat-error.log;

location / {

proxy_set_header X-Forwarded-Host $host;

proxy_set_header X-Forwarded-Server $host;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://127.0.0.1:8080/;

}

}

Save and exit the file when finished.

Now run the command below to activate the ‘tomcat10’ server block configuration and test your Nginx syntax.

sudo ln -s /etc/nginx/sites-available/tomcat10 /etc/nginx/sites-enabled/

sudo nginx -t

If you have correct and proper Nginx syntax, you will see an output ‘syntax is ok … test is successful‘.

<img alt="nginx reverse proxy tomcat" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/14-setup-reverse-proxy.png664736bc27a85.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="141" loading="lazy" src="data:image/svg xml,” width=”750″>

Next, run the following command to restart the Nginx service and apply the ‘tomcat10’ server block. Then, verify the Nginx service status to ensure it is running.

sudo systemctl restart nginx

sudo systemctl status nginx

The output below shows that the Nginx web server is running. And you can access your Apache Tomcat installation using a domain name such as ‘tomcat10.hwdomain.io‘.

<img alt="check nginx service" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/15-check-nginx.png664736bc6216b.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="220" loading="lazy" src="data:image/svg xml,” width=”750″>

You can add the following configuration to the ‘hosts’ file on your local machine. For Linux or Mac users, add the following to the ‘/etc/hosts‘ file. As for Windows users, add the configuration below to the ‘C:WindowsSystem32driversetchosts‘ file.

192.168.5.30 tomcat10.hwdomain.io

Lastly, visit http://tomcat10.hwdomain.io using your web browser. If your Nginx reverse proxy installation is successful, you will see the Apache Tomcat index page like the following:

<img alt="tomcat index" data-ezsrc="https://kirelos.com/wp-content/uploads/2024/05/echo/13-vhost.png664736bcb79a3.jpg" ezimgfmt="rs rscb10 src ng ngcb9" height="321" loading="lazy" src="data:image/svg xml,” width=”750″>

Visit http://tomcat10.hwdomain.io/host-manager/ to access the Apache Tomcat host-manager and http://tomcat10.hwdomain.io/manager/ to access the Apache Tomcat manager. You will see both applications running under the Nginx reverse proxy.

Conclusion

Congratulations! You have successfully installed Apache Tomcat on Ubuntu 24.04 server. You’ve installed Tomcat 10 with the Java OpenJDK 21 on Ubuntu. Also, you have installed and configured Nginx as a reverse proxy for Apache Tomcat.