Search

Easy Steps on How to Install Tomcat Ubuntu Server 23

Welcome to our step-by-step guide on how to install Tomcat on your Ubuntu server 23. Tomcat is an open-source web application server that is perfect for hosting Java-based applications. Whether you're a beginner or an experienced developer, this tutorial will walk you through all the necessary steps to get Tomcat up and running on your Ubuntu server.

By following our guide, you'll learn how to set up the environment, install the required JDK, download and extract Tomcat, configure user accounts, and start the Tomcat service. We'll make sure that you have all the information you need to successfully install Tomcat and begin hosting your Java web applications.

So, let's get started with our easy-to-follow guide on Tomcat installation on Ubuntu. By the end of this tutorial, you'll have a powerful platform ready to deploy your Java-based web applications. Let's dive in!

Prerequisites for Tomcat Installation

Before you start installing Tomcat on your Ubuntu server 23, there are a few prerequisites you need to take care of. First and foremost, make sure you have a fresh installation of Ubuntu 23. If you haven't installed Ubuntu yet, you can follow our guide on how to install Ubuntu on your server.

Additionally, you'll need to have a user account with sudo or root privileges. This will allow you to execute administrative tasks during the installation process. If you don't have a user account with these privileges, you can create one by following the instructions provided by Ubuntu.

Finally, it's essential to have Java Development Kit (JDK) 11 or later installed on your system. Tomcat 10 requires JDK 11 or newer, so make sure you have the correct version installed before proceeding with the installation. If you haven't installed JDK yet, don't worry, we'll guide you through the process later in this article.

Now that you have all the prerequisites in place, you're ready to move on to the next steps of installing Tomcat on your Ubuntu server 23.

Updating Package Lists and Upgrading Packages

Before proceeding with the installation of Tomcat on your Ubuntu server 23, it is important to ensure that your package lists are up to date and that all packages are upgraded to their latest versions. This will help to avoid any compatibility issues and ensure that you have the most secure and stable environment for running Tomcat.

To update your package lists and upgrade your packages, simply open your terminal and run the following command:

sudo apt update && sudo apt upgrade -y

This command will first update the package lists on your system, retrieving the latest information about available packages. It will then proceed to upgrade any installed packages to their latest versions, ensuring that you have the most current software installed.

By regularly updating your package lists and upgrading your packages, you can take advantage of bug fixes, security patches, and new features that are released by the Ubuntu community. This helps to keep your system optimized and protected against potential vulnerabilities.

Installing OpenJDK 11 on Ubuntu: A Step-by-Step Tutorial

Once you have set up your Ubuntu server 23, the next step in installing Tomcat is to install OpenJDK 11. OpenJDK is a free and open-source implementation of the Java Development Kit, which is required for running Tomcat.

To install OpenJDK 11 on your Ubuntu server, follow these simple steps:

  1. Open a terminal window or command line on your Ubuntu server.
  2. Run the following command:
  3. Enter your password when prompted and press Enter. This will start the installation process.
  4. Wait for the installation to complete. This may take a few minutes.
  5. Once the installation is finished, you can verify that OpenJDK 11 is installed by running the command:
  6. If everything is successful, you should see the version information for OpenJDK 11 displayed in the terminal.

Congratulations! You have successfully installed OpenJDK 11 on your Ubuntu server. This is an essential step in setting up Tomcat and ensures that your server is ready to run Java-based applications.

Why OpenJDK 11?

OpenJDK 11 is the recommended version for running Tomcat 10. It provides improved performance, security updates, and compatibility with the latest Java features. By installing OpenJDK 11, you can take advantage of these benefits and ensure that your Tomcat installation is optimized for performance and security.

Downloading and Extracting Tomcat 10

Once you have ensured that all the prerequisites are in place, it's time to download and extract Tomcat 10 on your Ubuntu server. Follow the steps below to get started:

  1. Go to the official Apache Tomcat download page.
  2. Look for the latest stable version of Tomcat 10 and click on the download link.
  3. Save the tar.gz file to the /tmp directory on your Ubuntu server.
  4. Open a terminal window and navigate to the /tmp directory.
  5. Use the wget command to download the Tomcat tar.gz file. For example:
    wget https://example.com/tomcat-10.1.10.tar.gz
  6. Wait for the download to complete.
  7. Once the download is finished, navigate to the /opt directory by running the command:
    cd /opt
  8. Create a new directory for Tomcat by running the command:
    sudo mkdir tomcat
  9. Extract the contents of the tar.gz file to the /opt/tomcat directory using the following command:
    sudo tar -xf /tmp/tomcat-10.1.10.tar.gz -C /opt/tomcat --strip-components=1

Remember to replace "10.1.10" in the commands above with the version number you downloaded.

Once you have successfully downloaded and extracted Tomcat 10, you are ready to proceed with the configuration and setup of user accounts.

Configuring Tomcat User Accounts

Once you have successfully installed Tomcat on your Ubuntu server 23, it's important to configure user accounts to ensure security and control access to the Tomcat admin and manager pages. By following these steps, you can secure your Tomcat installation and restrict unauthorized access.

Step 1: Create a Dedicated Tomcat User

In order to enhance security, it is recommended to create a dedicated system user specifically for running Tomcat. This user should have limited privileges and should not have a shell login. To create the user, open a terminal and run the following command:

sudo adduser --no-create-home --disabled-login --gecos "" tomcat

Step 2: Grant User Roles

Next, you need to grant the necessary roles to the Tomcat user. Open the tomcat-users.xml configuration file located in /opt/tomcat/conf/ using a text editor. Add the following lines inside the <tomcat-users> element:

<role rolename="manager-gui"/>

<role rolename="admin-gui"/>

<user username="tomcat" password="your_password" roles="manager-gui,admin-gui"/>

Replace "your_password" with a strong password of your choice for the Tomcat user.

Step 3: Save and Restart Tomcat

Save the tomcat-users.xml file and restart Tomcat to apply the changes. In the terminal, run the following command:

sudo systemctl restart tomcat

By configuring user accounts and defining the necessary roles, you have now secured the admin and manager pages of your Tomcat installation. This ensures that only authorized users can access and manage your Tomcat server.

Modifying Configuration Files for Remote Access

Modifying the configuration files of Apache Tomcat allows you to enable remote access to the Tomcat manager and host-manager applications. By default, these applications are accessible only from localhost, but if you want to allow connections from anywhere, you need to make a few changes.

To modify the configuration files, navigate to the conf directory in your Tomcat installation. Look for the context.xml files for both the manager and host-manager applications. Open these files in a text editor and locate the section that specifies IP address restrictions.

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

Within each file, you'll find a line similar to the one shown above. To allow remote access, you need to comment out this line. To do so, add at the end, effectively disabling the IP address restriction.

Once you have made the necessary changes, save the configuration files and restart your Tomcat server. You should now be able to access the Tomcat manager and host-manager applications from remote machines using a web browser.

Creating a Systemd Service File for Tomcat

Once you have successfully installed Tomcat 10 on your Ubuntu server 23, it's time to create a systemd service file to manage the Tomcat service with ease. By creating a service file, you'll be able to start, stop, and restart Tomcat using the systemctl commands, simplifying the administration of your server. Here's how you can do it:

  1. Open a text editor and create a new file with the following command: sudo nano /etc/systemd/system/tomcat.service.
  2. Paste the following configuration into the file:

[Unit]
Description=Tomcat 10
After=network.target

[Service]
Type=forking
User=tomcat
Group=tomcat
Environment=CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat/latest
Environment=CATALINA_BASE=/opt/tomcat/latest
ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

  1. Save the file and exit the text editor.
  2. Reload the systemd daemon to ensure the new service file is recognized: sudo systemctl daemon-reload.
  3. You can now start, stop, and restart Tomcat using the following commands:

sudo systemctl start tomcat
sudo systemctl stop tomcat
sudo systemctl restart tomcat

With the systemd service file in place, you have a convenient way to manage your Tomcat service on Ubuntu server 23. Enjoy the flexibility and control it brings to your web application deployment process!

Checking Firewall Settings and Allowing Incoming Connections

Once you have successfully installed Tomcat 10 on your Ubuntu server 23, it's important to check your firewall settings to ensure that incoming connections to Tomcat are allowed. By default, the Tomcat server listens on port 8080, so you need to make sure that your firewall is not blocking this port.

If you are using UFW, the Uncomplicated Firewall, you can use the following command to allow incoming connections to port 8080:

sudo ufw allow 8080

If you are using FirewallD, the firewall management tool for Linux systems with systemd integration, you can run the following command:

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

Lastly, if you are using iptables, the traditional Linux firewall utility, you can use the following commands:

sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
sudo iptables-save | sudo tee /etc/iptables/rules.v4

By allowing incoming connections to port 8080, you will be able to access your Tomcat server from other devices on your network or from the internet, depending on your network configuration and security requirements.

Conclusion

Congratulations on successfully installing Tomcat 10 on your Ubuntu server 23! By following the step-by-step guide outlined in this article, you have now set up a powerful platform for hosting Java-based web applications.

To summarize the installation steps, you started by ensuring you had the necessary prerequisites, including a fresh installation of Ubuntu 23 and Java Development Kit (JDK) 11 or later. Then, you updated your package lists and upgraded existing packages for a smooth installation process.

Next, you installed OpenJDK 11 and downloaded the latest version of Tomcat 10 from the Apache Tomcat official download page. After extracting the files and configuring user accounts, you modified the necessary configuration files to enable remote access and created a systemd service file for efficient management of the Tomcat service.

Remember to regularly update both your system and Tomcat to benefit from the latest features and security patches. Now, you can start building and deploying your Java web applications using Tomcat. Enjoy the power and flexibility that Tomcat provides for your hosting needs!

Sys Admin

Sys Admin

I am a Red Hat Certified Engineer (RHCE) and working as an IT Professional since 2012...