Skip to main content

Installation and Configuration of Apache Tomcat 8.5.14

Apache Tomcat commonly called as Tomcat is an open-source web server and servlet container developed by Apache Software Foundation. It is written primarily in Java and released under Apache License 2.0. This is a cross platform application.
Recently, on April 18th, 2017, Apache Tomcat reached to version 8 (i.e. 8.5.14), which includes a numerous fixes and number of other enhancements and changes. Some of noticeable changes included in this release are: support for Java Servlet 3.1, JSP (JavaServer Pages) 2.3, EL (Java Expression Language) 3.0, Java Websocket 1.1, etc.

Components of Tomcat

  1. Catalina : It is the Servlet Container of Tomcat.
  2. Coyote : Coyote acts as a connector and supports HTTP 1.1
  3. Jasper : It is the Tomcat’s JSP Engine.
  4. Cluster : A component for load balancing to manage large applications.
  5. High availability : A Tomcat component to schedule system upgrades and changes without affecting live environment.
  6. Web Application : Manage Sessions, Support deployment across different environments.
This article will walk you throughout the process of installing Apache Tomcat 8 (i.e. 8.5.14) on Linux systems, which includes RHEL, CentOS, Fedora, Debian, Ubuntu, etc.

Step 1: Installing Java 8

1. Before installing Tomcat make sure you have the latest version of Java Development Kit (JDK) installed and configured on the system. It is preferred to use oracle Java.
To install latest Oracle Java JDK (jdk-8u131) on Linux, you may like to refer our recent posts on Oracle jdk/jre/jar installations here:
  1. Install Java 8 JDK on Linux
  2. Install Java 8 JDK/JRE on RHEL/CentOS

Step 2: Download and Install Apache Tomcat 8

2. Once latest Java installed and configured correctly on the system, we will move forward to download and install latest stable version of Tomcat 8 (i.e. 8.5.14). If you want to cross check, if any newer version available, go to following Apache download page and cross check.
  1. http://tomcat.apache.org/download-80.cgi
3. Next create a /opt/tomcat/ directory and download the latest version of Apache Tomcat 8 under this directory, also for cross checking the download file, we will be downloading hash file. The download will take some time depending upon your connection speed.
# mkdir /opt/tomcat/ && cd /opt/tomcat 
# wget http://mirror.fibergrid.in/apache/tomcat/tomcat-8/v8.5.14/bin/apache-tomcat-8.5.14.zip 
# wget https://www.apache.org/dist/tomcat/tomcat-8/v8.5.14/bin/apache-tomcat-8.5.14.zip.md5
Note: Make sure to replace the version number in the above download link with the latest version available if it was different.
4. Now verify the MD5 Checksum against the key.
# cat apache-tomcat-8.5.14.zip.md5 
# md5sum apache-tomcat-8.5.14.zip
Make sure that the output (Hash Value) matches, as shown below.
Verify Apache Tomcat MD5
Verify Apache Tomcat MD5
5. Extract the Tomcat zip and cd to ‘apache-tomcat-8.5.14/bin/‘ directory.
# unzip apache-tomcat-8.5.14.zip
# cd apache-tomcat-8.5.14/bin/
6. Now make Linux scripts executable that is under ‘apache-tomcat-8.5.14/bin/‘ and then create symbolic link of startup and shutdown script for tomcat as:
Change all scripts *.sh executable only for root as,
# chmod 700 /opt/tomcat/apache-tomcat-8.5.14/bin/*.sh
Create Symbolic link for startup script as,
# ln -s /opt/tomcat/apache-tomcat-8.5.14/bin/startup.sh /usr/bin/tomcatup
Create Symbolic link for shutdown script as,
# ln -s /opt/tomcat/apache-tomcat-8.5.14/bin/shutdown.sh /usr/bin/tomcatdown
7. Now to start tomcat, you just need to fire the below command as root from anywhere in the shell.
# tomcatup
Sample Output
Using CATALINA_BASE:   /opt/tomcat/apache-tomcat-8.5.14
Using CATALINA_HOME:   /opt/tomcat/apache-tomcat-8.5.14
Using CATALINA_TMPDIR: /opt/tomcat/apache-tomcat-8.5.14/temp
Using JRE_HOME:        /opt/java/jdk1.8.0_131/jre/
Using CLASSPATH:       /opt/tomcat/apache-tomcat-8.5.14/bin/bootstrap.jar:/opt/apache-tomcat-8.5.14/bin/tomcat-juli.jar
Tomcat started.
Once ‘Tomcat Started‘, you can point your browser to http://127.0.0.1:8080 and you should see something as:
Default Apache Tomcat Page

Step 3: Changing Apache Tomcat Port

8. Do remember that 8080 is the default port tomcat usages. To change tomcat port from 8080 to any other unused port (say 137), you may do as:
First shutdown tomcat server simply by typing the below command from anywhere in the shell.
# tomcatdown
Next, open ‘/opt/tomcat/apache-tomcat-8.5.14/conf/server.xml‘ file in your favorite editor (mine is nano) to edit. Change port 8080 to 137, save and exit.
# nano /opt/tomcat/apache-tomcat-8.5.14/conf/server.xml
Sample Output
 <Connector port="137" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
After changing port to 137, restart tomcat service again and point your browser to http://127.0.0.1:137.
# tomcatupSimilarly, you can use any port of your choice. Make sure the port you are using don’t conflict with any other application/resource.

Step 4: Configuring Apache Tomcat 8

9. By default the Tomcat page is accessed by you only due its security implementation so that unauthorized users don’t have access to it.
To access admin and other sections like Server Status, Manager App and Host Manager. You need to add user accounts for admins and managers.
To add a Tomcat user edit file ‘/opt/tomcat/apache-tomcat-8.5.14/conf/tomcat-users.xml‘, in your favorite editor.
# nano /opt/tomcat/apache-tomcat-8.5.14/conf/tomcat-users.xml
10. Add the following lines just before ‘</tomcat-users>‘.
<role rolename="admin-gui"/>
<user username="admin" password="tecmint" roles="admin-gui"/>
<role rolename="manager-gui"/>
<user username="avi" password="tecmint123" roles="manager-gui"/>
Add Tomcat Users
Add Tomcat Users
Again, you need to restart Tomcat to take new changes into effect.
# tomcatdown
# tomcatup
11. After restarting Tomcat, make sure to access the admin other sections like Server Status, etc at http://127.0.0.1:137.
It you will be asked to Enter User_name and Password, you just created above, after login you will see something like the below interface.
Apache Tomcat User Login
Apache Tomcat Server Status
Your all setting and basic configuration of Tomcat has finished now. Now we will see a simple example (beyond the scope of this article), a very basic program (JSP Program) to run in Tomcat. It would be dumb if we do not show it.
12. Create a file called tecmint.jsp under ‘/opt/tomcat/apache-tomcat-8.5.14/webapps/ROOT‘ directory.
# touch /opt/tomcat/apache-tomcat-8.5.14/webapps/ROOT/tecmint.jsp
13. Now put the below contents in the new file (tecmint.jsp), save and exit. You may edit it, if you know what you are doing.
<html>
<head>
<title>Tecmint post:TomcatServer</title>
</head>
<body>
<START OF JAVA CODES>
<%
out.println("Hello World! I am running my first JSP Application");
out.println("<BR>Tecmint is an Awesome online Linux Resource.");
%>
<END OF JAVA CODES>
</body>
</html>
Create JSP Program
Create JSP Program
Most of the things in the above codes are self explaining. We have put simple Java code to print two lines of output and embed it in between HTML codes, which can be accessed at http://127.0.0.1:137/tecmint.jsp.
JSP Page
Congratulations! You have successfully run your Tomcat Application. That’s all for now from me. We are just exploring if our readers are interested in a detailed JAVA Tutorial on Tecmint. Please let us know your valuable thoughts in the comments below. Like and share us and help us get spread.

Comments