How to install Apache Tomcat in ubuntu 16.04 LTS

Apache Tomcat is a web worker and servlet compartment that is utilized to serve Java applications. Tomcat is an open source usage of the Java Servlet and JavaServer Pages advancements, delivered by the Apache Software Foundation. This instructional exercise covers the essential establishment and some design of the most recent arrival of Tomcat 8 on your Ubuntu 16.04/18.04 worker.

In this post, We will install and configure Apache Tomcat 8 on ubuntu 16.04/18.04.

Step 1: Update and Upgrade the System

In our first step, We need to update the ubuntu current repository and upgrade the packages by using the following commands.

sudo apt-get update
sudo apt-get upgrade -y

Step 2: Installing Java

Apache Tomcat run on java so that’s why we need to install Java packages by using the following command.

sudo apt-get install default-jdk -y

after installation of java packages, You need to verify the java version by using the following command.

java -version

Step 3: Creating User and group

For security purposes, Tomcat should be run as an unprivileged client (for example not root). We will make another client and gathering that will

run the Tomcat administration.

Create group for the tomcat by using the following command.

sudo groupadd tomcat

Now we need to create a system using for the tomcat use the following command for that.

sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat

Here our system user creation is completed.

Step 4: Download Apache Tomcat 8

The most ideal approach to introduce Tomcat 8 is to download the most recent parallel delivery at that point design it physically.

Locate the most recent variant of Tomcat 8 at the Tomcat 8 Downloads page. At the hour of composing, the most recent form is 8.5.5, however you should utilize a later steady form in the event that it is accessible. Under the Binary Distributions area, at that point under the Core list, duplicate the connection to the “tar.gz”.

cd /tmp
curl -O https://downloads.apache.org/tomcat/tomcat-8/v8.5.61/bin/apache-tomcat-8.5.61.tar.gz

We will move Tomcat extracted files to the /opt/tomcat directory, To do that use the following command for that.

sudo mkdir /opt/tomcat
sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
Step 5: Update the permission
Now you need to update the tomcat permission to access on /opt/tomcat directory, Use the following commands to do that.
cd /opt/tomcat
sudo chgrp -R tomcat /opt/tomcat
sudo chmod -R g+r conf
sudo chmod g+x conf
sudo chown -R tomcat webapps/ work/ temp/ logs/

Step 6: Creating SystemD service

To control Apache tomcat service we need to create systemd service by following the given commands, First we need to get the Java HOME_PATH.

sudo update-java-alternatives -l

You should get output like this :-

Here you need to copy the JAVA_HOME path that use in Apache Tomcat service, Now you need to create a configuration named tomcat.service in the /etc/systemd/system directory by using the following command.
sudo nano /etc/systemd/system/tomcat.service

and paste the given following configure.

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

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre
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

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

Save and exit from the nano text editor.

Now we need to reload the daemon by using the following the command.

sudo systemctl daemon-reload

To start the Apache tomcat service.

sudo systemctl start tomcat

To get the Apache Tomcat service status.

sudo systemctl status tomcat

You should get the output like this.

As we can see that Apache tomcat service and up and running state, Now we need to enable this service on boot also, Use the following command.

sudo systemctl enable tomcat

Step 7: UFW Rules

In this step, We need to open the port 8080 for http to web access of Apache Tomcat 8 on our ubuntu server, Use the following command for that.

sudo ufw status
sudo ufw allow 8080

Now we can access the Apache tomcat web user interfaces on given URL.

http://IP_Address:8080 or http://localhost:8080

You should get the web page like this.

Conclusion

Your establishment of Tomcat is finished! Your are presently allowed to send your own Java web applications!

How to install Apache Tomcat in ubuntu 16.04 LTS

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top