In this article, we will have explained the necessary steps to install and configure Tomcat on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.
Apache Tomcat is an open-source web server and Java servlet container. It is one of the most popular choices for building Java-based websites and applications. Tomcat is lightweight, easy to use, and has a robust ecosystem of add-ons.
Install Tomcat on Ubuntu 20.04
Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.
Step 2. Install Java.
Java is required for Tomcat to serve Java applications. You can install Java 11 using the following command:
You can verify the installation with:
Step 3. Create Tomcat Service Account.
First, create a new tomcat group called tomcat:
Next, run the commands below:
Step 4. Install Apache Tomcat.
Now download the latest binary release of Tomcat for the official Tomcat downloads page:
Then, Setup correct permissions for tomcat user:
Step 5. Create Systemd Unit File.
To run Tomcat as a service you need to setup this with a systemd service file. We are going to use tomcat as a service so we need to create a tomcat service file. But before that, we have to find the location where java is installed we will use this path in the tomcat service file. Use the following command to locate it:
Now copy the highlighted string and paste it in JAVA_HOME variable. And add /jre at the end of the string So that the whole string should look like this:
java-1.11.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.11.0-openjdk-amd64
Next, create a systemd service file with the following command:
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
After that, run the commands below to reload systemd profiles and enable tomcat service:
Step 7. Configure Firewall.
Tomcat uses port 8080 to accept the requests. Allow the traffic to this port with the following command:
Step 8. Test the Tomcat Installation.
To test tomcat open a browser and type the domain or IP of the server followed by :8080. Type the following:
You should get following output for successful installation:
That’s all you need to do to install Tomcat on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. Don’t forget to share your valuable queries/suggestions in the below comment box & also drop your worthwhile feedback.