Apache Tomcat is an open-source web server and servlet container developed by the Apache Software Foundation. It is used to deploy Java-based web applications. In this guide, we will show you how to install and configure Apache Tomcat on Ubuntu 22.04. Whether you are setting this up locally or using a Windows VPS UK, these steps will help you get started.
Step 1: Update Your System
Before installing Apache Tomcat, make sure your system is up to date. Run the following commands:
sudo apt update && sudo apt upgrade -y
It is crucial to keep your system updated for security and performance, especially if you are running it on a VPS Windows Servers platform.
Step 2: Install Java
Apache Tomcat requires Java to run. Install the latest OpenJDK package by running:
sudo apt install openjdk-11-jdk -y
Verify the Java installation:
java -version
Step 3: Create a Tomcat User
For security reasons, it is a good idea to run Tomcat under a separate user. Create a new user and group for Tomcat:
sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
Step 4: Download and Install Apache Tomcat
Go to the official Apache Tomcat website to download the latest version. Use the following command to download Tomcat:
cd /tmp
wget https://downloads.apache.org/tomcat/tomcat-10/v10.1.0/bin/apache-tomcat-10.1.0.tar.gz
Extract the downloaded file to the /opt/tomcat
directory:
sudo mkdir /opt/tomcat
sudo tar xzvf apache-tomcat-10.1.0.tar.gz -C /opt/tomcat --strip-components=1
Step 5: Configure Permissions
Set the correct permissions for the Tomcat directory:
sudo chown -R tomcat: /opt/tomcat
sudo chmod -R 755 /opt/tomcat
Step 6: Create a Systemd Service File for Tomcat
Create a systemd service file to manage the Tomcat service:
sudo nano /etc/systemd/system/tomcat.service
Add the following content to the file:
[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
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"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
Environment="JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom"
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
Save and close the file.
Reload systemd to apply the new service file:
sudo systemctl daemon-reload
Step 7: Start Tomcat Service
Start and enable the Tomcat service:
sudo systemctl start tomcat
sudo systemctl enable tomcat
Check the status of the Tomcat service:
sudo systemctl status tomcat
Step 8: Configure Firewall (Optional)
If you have UFW (Uncomplicated Firewall) enabled, allow traffic on port 8080, which Tomcat uses:
sudo ufw allow 8080
Step 9: Access Tomcat Web Interface
You can now access the Tomcat web interface by opening your browser and navigating to:
http://:8080
You should see the Apache Tomcat default page, indicating that Tomcat is successfully installed.