How To Install Tomcat 8 On Ubuntu 14.04 And 14.10

Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies. The Java Servlet and JavaServer Pages specifications are developed under the Java Community Process. Apache Tomcat is developed in an open and participatory environment and released under the Apache License version 2. Apache Tomcat is intended to be a collaboration of the best-of-breed developers from around the world. Apache Tomcat powers numerous large-scale, mission-critical web applications across a diverse range of industries and organizations.

Install Tomcat 8 on Ubuntu

In this tutorial, let us see how to install Tomcat 8 on Ubuntu 14.04 and 14.10. Also, the same method will work on other Ubuntu derivatives.

My machine:

Linux ubuntu 3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

My Ip =   192.168.64.130

Install OpenJDK:

Install Java using command:

unixmen@ubuntu:~$ sudo apt-get install openjdk-7-jdk

You can also verify it, by issuing the following command.

unixmen@ubuntu:~# java -version
java version "1.7.0_75"
OpenJDK Runtime Environment (IcedTea 2.5.4) (7u75-2.5.4-1~trusty1)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)

Download & Setup Apache Tomcat:

Download the latest version of the Apache Tomcat from the website and save it on your home directory.

unixmen@ubuntu:~$ wget http://www.apache.org/dist/tomcat/tomcat-8/v8.0.21/bin/apache-tomcat-8.0.21.tar.gz
unixmen@ubuntu:~# wget http://www.apache.org/dist/tomcat/tomcat-8/v8.0.21/bin/apache-tomcat-8.0.21.tar.gz
--2015-03-29 15:37:40-- http://www.apache.org/dist/tomcat/tomcat-8/v8.0.21/bin/apache-tomcat-8.0.21.tar.gz
Resolving www.apache.org (www.apache.org)... 104.130.219.184, 88.198.26.2, 192.87.106.229, ...
Connecting to www.apache.org (www.apache.org)|104.130.219.184|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9146280 (8.7M) [application/x-gzip]
Saving to: ‘apache-tomcat-8.0.21.tar.gz’
100%[===================================================================>] 9,146,280 1.70MB/s in 5.7s
2015-03-29 15:37:46 (1.54 MB/s) - ‘apache-tomcat-8.0.21.tar.gz’ saved [9146280/9146280]

Extract tomcat to /var/local/:

unixmen@ubuntu:~$ sudo tar -zxvf apache-tomcat-8.0.21.tar.gz -C /var/local/

Controlling Apache Tomcat:

Apache Tomcat can be started and stopped by the script which comes with package, start the Apache Tomcat.

unixmen@ubuntu:~# sudo /var/local/apache-tomcat-8.0.21/bin/startup.sh
Using CATALINA_BASE: /var/local/apache-tomcat-8.0.21
Using CATALINA_HOME: /var/local/apache-tomcat-8.0.21
Using CATALINA_TMPDIR: /var/local/apache-tomcat-8.0.21/temp
Using JRE_HOME: /usr
Using CLASSPATH: /var/local/apache-tomcat-8.0.21/bin/bootstrap.jar:/var/local/apache-tomcat-8.0.21/bin/tomcat-juli.jar
Tomcat started.
unixmen@ubuntu:~#

You can verify the service running, by default tomcat runs on port no 8080.

unixmen@ubuntu:~# sudo netstat -tulpn | grep 8080
tcp6 0 0 :::8080 :::* LISTEN 23967/java
unixmen@ubuntu:~#

Open the web browser and point to http://ipaddress:8080

tomcat

How to stop the Apache Tomcat?

unixmen@ubuntu:~$ sudo /var/local/apache-tomcat-8.0.21/bin/shutdown.sh

Managing the Apache Tomcat:

Tomcat can be managed through the web-manager.

Web manager is password protected, requires user name and password to access. Only the user with the “manager-gui” role is allowed to access, these users and roles are defined in tomcat-users.xml. By default “manager-gui” role not defined that file, you have  to add it manually.

unixmen@ubuntu:~$ sudo  vi /var/local/apache-tomcat-8.0.21/conf/tomcat-users.xml

Add the following:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
</tomcat-users>
~

Restart the tomcat to  have access to the web manager.

tomcat2

That’s it.

You might want to read the following articles about Tomcat: