0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

**Installing Apache Tomcat on Ubuntu 24.04**

0
Posted at

Apache Tomcat is an open-source application server that serves Java-based applications. It is one of the most widely used web servers for hosting Java Servlets and JavaServer Pages (JSPs). If you're setting up Tomcat on your Ubuntu 24.04 server, follow these detailed steps to get it up and running.

Prerequisites

  • Ubuntu 24.04 server (you can use VPS or local installation)
  • A user with sudo privileges
  • Basic understanding of command-line operations

Step 1: Update the System

Start by updating your system’s package list to ensure that you have the latest updates and security patches.

sudo apt update
sudo apt upgrade -y

Step 2: Install Java Development Kit (JDK)

Tomcat requires a Java runtime environment to run. The latest version of Tomcat (at the time of writing) supports Java 8 and later. We'll install OpenJDK 11, which is fully supported.

sudo apt install openjdk-11-jdk -y

Check if Java was successfully installed:

java -version

Step 3: Create a Tomcat User

For security reasons, it’s a good idea to run Tomcat under a separate user. This minimizes the risk of security breaches affecting your entire system.

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

Step 4: Download Apache Tomcat

Visit the Apache Tomcat download page and copy the link to the latest version of Tomcat 9.

Alternatively, use wget to download the binary distribution directly to your server:

cd /tmp
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.53/bin/apache-tomcat-9.0.53.tar.gz

Step 5: Extract and Install Tomcat

After downloading, extract the tar file and move it to the /opt/tomcat directory.

sudo tar xzvf apache-tomcat-9.0.53.tar.gz -C /opt/tomcat --strip-components=1

Step 6: Set Permissions

Now, change the ownership of the Tomcat directory to the tomcat user and group.

sudo chown -R tomcat: /opt/tomcat

Step 7: Configure Tomcat as a Service

To make sure Tomcat starts automatically when the system boots, create a new systemd service file.

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

Add the following content:

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

[Service]
User=tomcat
Group=tomcat
Type=forking
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

[Install]
WantedBy=multi-user.target

Save and close the file. Now, reload the systemd manager and enable the Tomcat service:

sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl enable tomcat

Step 8: Configure Firewall

If you're using UFW, you will need to allow access to Tomcat's default ports (8080 and 8009).

sudo ufw allow 8080
sudo ufw allow 8009

Step 9: Test Tomcat

Now that everything is set up, test Tomcat by opening your web browser and going to:

http://<your_server_ip>:8080

You should see the Apache Tomcat default page.

Additional Resources

For more advanced configurations and troubleshooting, refer to this helpful guide: Install Tomcat on Ubuntu 24.04. This guide covers a wider range of installation options and best practices.


I hope this guide helps you set up Tomcat on your Ubuntu 24.04 server! Feel free to reach out if you encounter any issues.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?