How to Install Apache Tomcat on Ubuntu 24.04 Cloud Servers

2025-02-10 By Nathan 719 Views linux ubuntu apache tomcat
1 reviews

Introduction

Apache Tomcat is an open-source web server application that provides developers with a secure and efficient platform for running Java applications. It implements the Java Servlet and JavaServer Pages (JSP) specifications, enabling the deployment and management of Java-based web applications on servers.

With features such as load balancing, clustering, and high availability, Apache Tomcat delivers reliable performance, making it well-suited for applications with varying workloads.

In this article, we will guide you through the process of installing Apache Tomcat on Ubuntu 24.04, enabling you to seamlessly run dynamic web applications on your LayerStack Cloud Servers.


Prerequisite:

  • Deploy an Ubuntu 24.04 Cloud Servers on LayerStack.

  • Access the server using SSH.

  • Update the server's packet index.


A. Installing Java OpenJDK

Apache Tomcat requires Java Development Kit (JDK) version 17 or later. To get started, follow the steps below to install the necessary OpenJDK version and set up a dedicated user to run Tomcat securely on your Cloud Servers.


  1. Install OpenJDK 17 on your server.

    # sudo apt install openjdk-17-jdk -y
    


    The command installs OpenJDK 17, a required Java development kit for running Apache Tomcat:

    tomcatubuntu1

  2. View the installed Java version.

    # java -version
    


    The command verifies the installed Java version to ensure OpenJDK 17 is correctly installed:

    tomcatubuntu2

  3. Create a new Tomcat group to use with the Apache Tomcat service.

    # sudo groupadd tomcat
    


    The command creates a new user group named tomcat for managing permissions related to Tomcat:

    tomcatubuntu3

  4. Create a new Tomcat user with /opt/tomcat as the home directory and a member of the Tomcat group.

    # sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
    

    tomcatubuntu4


The command creates a new system user named Tomcat with /opt/tomcat as the home directory and adds the user to the Tomcat group.


B. Installing Apache Tomcat and Configuration

Apache Tomcat is NOT included in the default Ubuntu package repositories. Follow the steps below to download the latest Apache Tomcat release and install it on your Cloud Servers.


  1. Visit the Apache Tomcat releases page and download the latest Apache Tomcat 11 release file. Use the command below to download version 11.0.1 directly:

    # wget –O https://dlcdn.apache.org/tomcat/tomcat-11/v11.0.2/bin/apache-tomcat-11.0.2.tar.gz
    


    This command downloads the Tomcat 11.0.1 release file to your server. Ensure you download the latest version to take advantage of updated features and configurations. Official Tomcat URL: https://dlcdn.apache.org/tomcat/

    tomcatubuntu5

  2. Create a dedicated Tomcat Directory in a system-wide location (E.g. /opt) to extract the package contents.

    # sudo mkdir /opt/tomcat
    

    tomcatubuntu6

  3. Extract the contents of the downloaded archive to the /opt/tomcat directory using the following command.

    # sudo tar -xvzf apache-tomcat-11.0.2.tar.gz -C /opt/tomcat --strip-components=1
    


    The command extracts the downloaded Tomcat archive into /opt/tomcat and removes the top-level directory from the archive:

    tomcatubuntu7

  4. Assign ownership of the /opt/tomcat directory to the Tomcat user and group.

    # sudo chown -R tomcat:tomcat /opt/tomcat
    


    The command changes ownership of the /opt/tomcat directory and its contents to the Tomcat user and group:

    tomcatubuntu8

  5. Grant the Tomcat group read permissions for the conf directory.

    # sudo chmod g+x /opt/tomcat/conf
    

    tomcatubuntu9


    With these steps completed, Apache Tomcat is now installed and ready for further configuration.


C. Creating Apache Tomcat Users

Apache Tomcat requires specific user accounts with administrative privileges to access the manager and host-manager applications in the web management dashboard. Follow the steps below to create privileged users and remove IP address restrictions, enabling access to these applications.


  1. Open the tomcat-users.xml configuration file using a text editor for editing.

    # sudo vim /opt/tomcat/conf/tomcat-users.xml
    

    tomcatubuntu10

  2. Add the following configurations above the /tomcat-users directive. Replace manager_password and admin_password with your desired passwords for the manager and admin users.


    <role rolename="manager-gui">
    <user username="manager" password="manager_password" roles="manager-gui">
    
    <role rolename="admin-gui">
    <user username="admin" password="admin_password" roles="manager-gui,admin-gui">
    


    This configuration creates two users:

  • A manager user with manager privileges for the Tomcat web management dashboard.

  • An admin user with both manager and administrator privileges.

    tomcatubuntu11

  1. Remove Manager Application Restrictions by opening the context.xml file for the manager application.

    # sudo vim /opt/tomcat/webapps/manager/META-INF/context.xml
    

    tomcatubuntu12


    Locate and disable the following Valve Directive by wrapping it in a <!-- Valve directive --> comment:

    <!--  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
    
    allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" ></Valve> -->
    


    Before:

    tomcatubuntu13


    After:

    tomcatubuntu14


    => Save and close the file, this change removes the IP address restrictions, allowing access to the manager application.

  2. Remove Host Manager Application Restrictions by opening the context.xml file for the host-manager application.

    # sudo vim /opt/tomcat/webapps/host-manager/META-INF/context.xml
    

    tomcatubuntu15


    Similarly, locate and disable the following Valve Directive by wrapping it in a <!-- Valve directive --> comment:

    <!--  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
    
    allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" ></Valve> -->
    


    Before:

    tomcatubuntu16


    After:

    tomcatubuntu17


    => Save and close the file, this change removes the IP address restrictions, enabling access to the host-manager application.


By completing these steps, you will have configured the necessary users with the appropriate privileges and removed access restrictions, making the manager and host-manager applications accessible on your server.


D. Setting Up Apache Tomcat as a System Service

Follow these steps to create a system service that run and manage Apache Tomcat processes on your Cloud Servers.


  1. Display the Java installation path.

    #  sudo update-java-alternatives -l
    

    tomcatubuntu18

  2. Create a new tomcat.service system service file by opening the system service file in a text editor.

    # sudo vim /etc/systemd/system/tomcat.service
    

    tomcatubuntu19


    Add these settings into the file and ensure you modify the JAVA_HOME value to match your Java installation path if it differs from the example provided:

    [Unit]  
    Description=Tomcat  
    After=network.target  
    
    [Service]  
    Type=forking  
    
    User=tomcat  
    Group=tomcat  
    
    Environment="JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64"  
    Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"  
    Environment="CATALINA_BASE=/opt/tomcat"  
    Environment="CATALINA_HOME=/opt/tomcat"  
    Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"  
    Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"  
    
    ExecStart=/opt/tomcat/bin/startup.sh  
    ExecStop=/opt/tomcat/bin/shutdown.sh  
    
    RestartSec=10  
    Restart=always  
    
    [Install]  
    WantedBy=multi-user.target
    

    tomcatubuntu20


    => Save and close the file.


The above configuration sets up a new Tomcat service that will start and stop the application using the startup.sh and shutdown.sh scripts located in the Apache Tomcat directory.

  1. Reload the systemd daemon to apply the new service configuration.

    # sudo systemctl daemon-reload
    

    tomcatubuntu21


    This command reloads the systemd manager configuration.

  2. Enable the Apache Tomcat service to start at boot.

    # sudo systemctl enable --now tomcat
    

    tomcatubuntu22


    The command sudo systemctl enable --now tomcat starts the Tomcat service immediately and enables it to start automatically at system boot.

  3. Verify Tomcat running status.

    # sudo systemctl status tomcat
    

    tomcatubuntu23


E. Accessing the Apache Tomcat Web Management Dashboard

Follow these steps to access the Apache Tomcat web management dashboard, where you can view and manage web applications on your Cloud Servers.


  1. Open any web browsers (E.g. Chrome) and visit your Apache Tomcat domain on port 8080.

    http://<ipaddress>:8080
    
    http://<domain>:8080
    

    tomcatubuntu24

    1. To access the Apache Tomcat manager application, click on Manager App. When prompted, enter your manager username and password to sign in.

      tomcatubuntu25

      tomcatubuntu26


    You should now be able to manage your Tomcat web applications and server settings. By following this guide, you will have successfully installed and configured Apache Tomcat on your Ubuntu 24.04 server, ensuring a smooth setup for running Java-based web applications.


Related Tutorials

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.