If you are looking to deploy your critical web applications on a web server, nothing could be better than Apache Tomcat.
Tomcat is a lightweight and widely used web server based on the implementation of Java servlets, JSP, and Java expression language. Tomcat provides a pure Java HTTP web server environment where java code runs. Many applications are hosted on tomcat as this is open-source, a victory for system operators.
In this tutorial, you will learn how to install Apache Tomcat 10.0 on an Ubuntu Linux machine.
Table of Contents
- How to Install Java 11 on ubuntu 18.04 machine
- How to Install Tomcat 10 on ubuntu 18.04 machine
- Files and Directories in Tomcat
This post will be a step-by-step tutorial. To follow along, be sure you have the following:
- An Ubuntu 14.04.4 LTS or greater Linux machine. This tutorial uses Ubuntu 18.04.5 LTS
Apache Tomcat is supported on all Windows, Linux, and macOS operating systems.
How to Install Java 11 on ubuntu 18.04 machine
As previously specified, Tomcat requires Java to be installed as tomcat implements Java-based technologies. If you don’t have java installed, let’s learn how to install Java Version 11 on the ubuntu 18.04 machine.
- Connect to Ubuntu machine using your favorite SSH client.
- Next, install java by running the apt
installcommand. default-jdk is an open source java runtime which is most widely used.
# Installing Java Version: Java SE 11 (LTS) sudo apt install default-jdk
- After apt install default-jdk command is executed successfully , verify if java has been installed successfully by running the below command.
java -version # To check the Installed Java Version
- To verify the Java you can also check the location of java binaries using which and whereis commands.
which java : # Provides the location of executable file whereis java # Provides location of all the files related to Java
- Run the below command to check the installation path of java. The system should respond with the path where Java is installed
update-alternatives --list java
If you have multiples Java installed on your machine and if you want to switch from one Java to another version consider running
update-alternatives --config javacommand.
How to install Tomcat 10 on ubuntu 18.04 machine
Now that you have Java installed successfully installed on the ubuntu 18.04 machine, which is great. Next, you need to install a tomcat. Installing Tomcat is a straightforward task; let’s checkout.
- Create a folder named tomcat inside the opt directory mkdir command.
cd /opt mkdir tomcat
- Download the Binary distribution of Tomcat 10 using
curlcommand as shown below..
curl -O https://mirrors.estointernet.in/apache/tomcat/tomcat-10/v10.0.4/bin/apache-tomcat-10.0.4.tar.gz
- Extract the tomcat archieve that you just downloaded using
tarcommand. After you execute the tar command you should see the tomcat folder in the opt directory.
sudo tar xzvf apache-tomcat-10.0.4.tar.gz -C /opt/tomcat --strip-components=1
- Now that you have tomcat installed but you should consider running tomcat as a tomcat user which should be the part of tomcat group.
- Creating a new group tomcat using
sudo groupadd tomcat
- Next, create a tomcat user using
useraddcommand and make it part of tomcat group .
- -s /bin/false denotes that nobody can login as this user
- /opt/tomcat will be tomcat home directory.
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
- To run tomcat as tomcat user assign the tomcat user and tomcat group to the tomcat directory.
cd /opt/tomcat # Go to tomcat directory sudo chgrp -R tomcat /opt/tomcat # tomcat group given group ownership on /opt/tomcat sudo chmod -R g+r conf # Assign Read permission to tomcat group on conf sudo chmod g+x conf # Assign Execute permission to tomcat group on conf sudo chown -R tomcat opt/tomcat # Assign tomcat as owner of the directory
- Now you are ready to start the tomcat application but it is always recommended to run the application using a service because the service saves applications to stop if the system reboots mistakenly or by any means. Let’s create the tomcat service.
- To create the tomcat service create a new file named tomcat.service as shown below.
sudo vi /etc/systemd/system/tomcat.service
- Next, copy and paste the below code in tomcat.service
[Unit] Description=Apache Tomcat After=network.target [Service] Type=forking Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-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 User=tomcat Group=tomcat UMask=0007 Restart=always [Install] WantedBy=multi-user.target
- Next, run the below commands to load the tomcat.service file & then start and enable the service.
sudo systemctl daemon-reload # This will load the file in systemd and it. sudo systemctl start tomcat # Start the tomcat service sudo systemctl enable tomcat # Enable the tomcat service sudo systemctl status tomcat # Enable the tomcat service
By now, Apache Tomcat 10 service should be started and running successfully. To verify the tomcat application, navigate to the default webpage on the browser and type <IP-address-of your-tomcat-server>:8080.
Make sure to check your inbound rules and if port 8080 is open.
In this tutorial, you have learned how to install Apache Tomcat on an Ubuntu server. Deploying Java applications on Apache Tomcat is a quick and easy process!
Apache Tomcat is the most widely used open-source tool for Java developers to run their web applications. Now, that you have installed Apache Tomcat which Java application are you going to deploy and manage next?