Installing Tomcat on Ubuntu Version 16.04


If you are using Java Hosting plans from HostingRaja, here you will get a detail information about to install Tomcat on Ubuntu version 16.04 follow the below-mentioned steps:

 

1)Update your system:

You need to have the latest version of Ubuntu 16.04 and use the command:

sudo apt-get update


Install Java and use the command:

sudo apt-get install default-jdk


2) You need to update the JAVA_HOME variable:


Find the directory for JAVA_HOME and use the command:

update-alternatives --config java


Copy the directory and type the following:

nano /etc/environment


It will open up with the file that consists of environment variables

Add JAVA_HOME.

JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"


The path which are in quotes is the path which you are using and then Save and close the file.


Reload the environment variables to take the effect.

source /etc/environment


You need to make sure that it has worked properly:

echo $JAVA_HOME

And you will be able to see the path you've entered.


3)Create the user to run the Tomcat web server


Let us assume the user as 'abcd'.

groupadd abcd

useradd -s /bin/false -g abcd -d /opt/abcd abcd


And you have to make sure that you know the version of Tomcat that you need to install


You need to make a directory for the Tomcat files:

mkdir /opt/tomcat


Download the Tomcat

cd

wget your-tomcat-link


You need to Unzip the files into the tomcat folder

tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1


You can also press the Tab key after typing the apache since you will be having only one download in your folder.


You need to also make sure that the folders have the right permissions.

cd /opt/

sudo chown -R tomcat tomcat/


Display the JAVA_HOME path once again, so that you will be able to copy it

nano /etc/systemd/system/tomcat.service


4) Configure the Tomcat


You need to copy and paste the settings below into the tomcat.service file that you have created.  And Edit the JAVA_HOME path to the one that you have copied. Later you need to save and close the file.


[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=abcd

Group=abcd

UMask=1234

RestartSec=10

Restart=always


[Install]

WantedBy=multi-user.target


And then Reload the SystemD daemon so the service settings which are added is been included.

sudo systemctl daemon-reload


Now you can start the Tomcat service.

sudo systemctl start tomcat


You need to check the status of your Tomcat server

sudo systemctl status tomcat


Browse to http://your-ip-address:2086


You will be able to see the Tomcat server landing page.

 

To install Tomcat on Ubuntu version 16.04 follow the below-mentioned steps: