Page tree
Skip to end of metadata
Go to start of metadata

Overview

Warnings:

  • We strongly recommend that only experienced Tomcat administrators install Tomcat.
  • If you select the MPM ITK option in the EasyApache 3 interface (Home >> Software >> EasyApache 3), you cannot install Tomcat.
  • The Tomcat service requires the you add the tomcat user to the nobody user group. If you already use Tomcat, EasyApache will change the group ID of the tomcat user to the nobody user group.
  • Tomcat is not available on servers that run CentOS 7, CloudLinux™ 7, or Red Hat® Enterprise Linux (RHEL) 7.
  • EasyApache 4 does not support Tomcat.

Note:

This document is for Tomcat 7. For information on Tomcat 5.5, read our Migrate from Tomcat 5.5 to Tomcat 7 documentation.

 

Apache Tomcat is an Apache module that provides a web server in addition to the Apache web server. The Tomcat web server supports Java Servlets and JavaServer pages.

For more information about the Apache Tomcat open-source project, visit the Apache Tomcat website.

How Tomcat works

EasyApache configures the Tomcat server to listen on port 8009, port 80, and, if you use SSL, port 443. The Tomcat web server listens on port 8080 for direct requests.

Important:

Your server's firewall must allow internal connections on port 8009.

For more information on the topics in the following sections, read Apache Tomcat's The Apache Tomcat Connector - Reference Guide documentation.

For more information on how Apache works, read our Apache documentation.

 

Warning:

We no longer develop EasyApache 3 and only release security updates. We will deprecate EasyApache 3 on December 31, 2018. After that date, we will no longer update EasyApache 3. In cPanel & WHM version 78, we will remove support for EasyApache 3. For more information, read our cPanel Long-Term Support documentation.

We strongly recommend that you upgrade to EasyApache 4. For more information, read our EasyApache 4 documentation. 

Featured documentation

  EasyApache 3

IntroductionFAQ

Change Log Release Notes  

ProfilesCustomization

Tomcat

Migrate from Tomcat 5.5 to 7

How to Deploy Java Applications

Important:

EasyApache 3 does not support Tomcat for new installations. EasyApache 4 does not support Tomcat and we do not plan to provide support in the future. 

Port 80 or 443

If a client browser sends a request on port 80 or 443, the Apache web server receives the request and the following actions occur:

  1. Apache reads the request. If the request is for content that requires the Tomcat web server, Apache translates the request from the HTTP protocol to the AJP protocol. Then, Apache sends the request to port 8009.

    Note:

    Apache can translate to the AJP protocol and send the request to port 8009 because of the configuration of the mod_jk Apache module.

  2. The Tomcat web server uses Tomcat's Apache connector with the AJP/1.3 protocol to listen on port 8009 for requests from Apache. It receives the request, reads it, translates the request so that a Tomcat worker can read it, and sends the request to a Tomcat worker.
  3. The Tomcat worker handles the request, and then returns the results of the request to the Tomcat's Apache connector on the Tomcat web server.
  4. Tomcat's Apache connector translates the results of the request so that the Apache web server can read it, and sends the results out of the Tomcat server on port 8009.
  5. Apache's Tomcat connector receives the results, translates it to the HTTP protocol, and directs the Apache web server to send the information to the browser client.

Diagram of process over port 80 or 443:

Port 8080

If a client browser sends a request on port 8080, the Tomcat web server responds to the request directly.

Note:

The Tomcat connector that listens on port 8080 uses the HTTP/1.1 protocol.

Diagram of process over port 8080:

How to install Tomcat

Installation requirements

You must have root-level access to install Tomcat. 

Remember:

Tomcat is  not available on servers that run CentOS 7, CloudLinux 7, or RHEL 7. 

Installation steps

Note:

In the following examples, example.com represents your domain.

Step 1: Install Tomcat

To install Tomcat, select the Tomcat 7 option in the Short Options List stage of WHM's EasyApache 3 interface (Home >> Software >> EasyApache 3.

EasyApache automatically inserts the mod_jk.so module directive into your Apache configuration.

Step 2: Enable Java servlets on your sites

Enable Java servlets via WHM

To enable Java servlets for a site via WHM, perform the following steps:

  1. Navigate to WHM's Install Servlets interface ( Home >> Account Functions >> Install Servlets).

    Important:

    This option does not appear until you install Tomcat on your server.

  2. Select the account in the Account Selection table and click Install.
  3. Navigate to the  http://www.example.com/jsptest.jsp  URL for your domain to test the installation.  

Notes:

  • You can only add servlet support to domains and subdomains.
    • To add servlet support to a parked domain (alias), add servlet support to the primary domain.
    • To add servlet support to an addon domain, add servlet support to the associated subdomain.
  • You cannot add servlet support to subdomains via WHM. Use the command line interface to add servlet support to subdomains.
Enable Java servlets via CLI

To enable Java servlets for a site via the command line, run the following command as the root user:

/scripts/addservlets --domain=example.com

To enable Java servlets for a subdomain or addon domain, run the following command on the associated subdomain:

/scripts/addservlets --domain=subdomain.example.com

If you enable Java servlets for a domain, cPanel & WHM performs the following actions:

  • cPanel & WHM creates a container for the site in the server.xml file.  
  • cPanel & WHM creates a default cp_jkmount.conf file for the site.
  • cPanel & WHM copies the jsptest.jsp file into the site’s document root.

To confirm that Java servlets work for the domain, navigate to the  http://www.example.com/jsptest.jsp  URL for your domain. The page should appear similar to the following example:

Example output from the jsptest.jsp  url

How to remove Tomcat servlets from a site

To remove Tomcat servlets from a site via the command line, run the following script as the root user:

/scripts/remservlets --domain=example.com

Note:

This script removes the container for the site from the /usr/local/easy/etc/easy-tomcat7/server.xml Tomcat server configuration file, and removes the cp_jkmount.conf site configuration file from each subdirectory for the domain within the /usr/local/apache/conf/userdata/ directory.

For example, the script removes cp_jkmount.conf file from the following directories:

  • /usr/local/apache/conf/userdata/std/2/$user/$domain/
  • /usr/local/apache/conf/userdata/ssl/2/$user/$domain/

How to deploy Java applications

After you enable Java servlets for a domain, the user can deploy Java applications on their web site. Java distributes many applications in convenient WAR packages that you can easily to install on your server.

For more information on how to deploy Java applications, read our How to Deploy Java Applications documentation.

How to manually deploy a WAR file

To manually deploy a WAR file, put the WAR file into the user's public_html directory. Once placed, you can access the application through the following address:  http://example.com:8080/appname

Then, add a JkMount entry for the application in the mod_jk file:

<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
JkMount /appname/* ajp13
</IfModule>

You must restart the httpd daemon to reload the mod_jk file with the new entry.

ROOT.war does not deploy automatically

ROOT.war does not deploy automatically. The index context of all cPanel & WHM hosts is hardcoded to the $CATALINA_HOME/conf/server.xml file.

For example: 

<Host name="reseller.example" appBase="/home/reseller/public_html">
<Alias>www.reseller.example</Alias>
<Context path="" reloadable="true" docBase="/home/reseller/public_html" debug="1"/>
<Context path="/manager" debug="0" privileged="true"
docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>

Tomcat components

Tomcat will install the following components on your server:

Component
Location
Description
The Java Development Kit (JDK)

The vendor RPM determines this location.

This directory contains the Java Runtime Environment (JRE).
The Binary Tomcat DistributionThe /usr/local/easy/share/easy-tomcat7/ directoryThis distribution is precompiled Java byte code, which Tomcat downloads and extracts. The $CATALINA_HOME  and $CATALINA_BASE variables point to this location.
Apache Tomcat Connectors (mod_jk)mod_jk.so in the Apache modules directoryThese connectors allow Apache to communicate with Tomcat.
cPanel-Provisioned Maintenance Scripts cPanel & WHM uses these maintenance scripts instead of the Tomcat initialization scripts. They create and remove Tomcat virtual hosts.

Important Tomcat files and directories

File name or directoryDescription
/var/log/easy-tomcat7/catalina.out
The Tomcat output log.
/var/log/easy-tomcat7/catalina.err

The Tomcat error log.

The error log marks errors with the following severity levels:

  • SEVERE
  • WARNING
  • INFO

The following command returns any SEVERE or WARNING level messages in the command line interface (CLI):

tail -f /var/log/easy-tomcat7/catalina.err | egrep -A2 '(SEVERE|WARNING):' &

Tomcat uses cPanel & WHM's default logging facility, Valve.

Tomcat also uses the CentOS-provided logrotate.d file to manage log rotation. Tomcat rotates logs weekly and keeps them for one year.

/usr/local/apache/logs/mod_jk.logApache's log for the mod_jk Apache module.
/var/cpanel/tomcat.options

Tomcat's options file.

Each argument in the options file is defined on a separate line, parsed, and then passed to jsvc (Commons Daemon).

  • For more information about JSVC Options in Tomcat, run the following command:

    /usr/local/easy/bin/jsvc -help
  • For more information about JVM Hotspot Options, read Oracle's Java HotSpot VM Options documentation.

/usr/local/easy/share/easy-tomcat7/conf/

The Tomcat server configuration file directory.

/usr/local/easy/share/easy-tomcat7/conf/server.xmlConfigures Virtual Hosts, Connectors, and more. While each instance of Tomcat has its own copy of the  server.xml file, cPanel & WHM only supports a single instance of the server.xml file.
/usr/local/apache/conf/jk.conf
The configuration file for the mod_jk Apache module. For more information on this file, read Apache Tomcat's Apache HTTP Server HowTo documentation.
/usr/local/easy/share/easy-tomcat7/conf/workers.properties Defines the parameters that Apache uses to communicate with Tomcat workers. For more information on this file, read Apache Tomcat's Apache HTTP Server HowTo documentation.

/usr/local/apache/conf/userdata/std/2/$user/$domain/cp_jkmount.conf

and

/usr/local/apache/conf/userdata/ssl/2/$user/$domain/cp_jkmount.conf

The site configuration file. This file exists for each site that uses Tomcat.

Each site with Java Servlets or JavaServer contains a cp_jkmount.conf file in the following directories:

  • /usr/local/apache/conf/userdata/std/2/$user/$domain/
  • /usr/local/apache/conf/userdata/ssl/2/$user/$domain/

The cp_jkmount.conf file contains a contextual path to the Tomcat worker that you wish the site to use.

When EasyApache builds your Apache configuration, it uses the following entry in the /usr/local/apache/conf/httpd.conf file to include the cp_jkmount.conf file in the VirtualHost tag for that site:

Include "/usr/local/apache/conf/userdata/std/$2/$user/$domain/*.conf"

The following is an example of a cp_jkmount.conf file:

<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
</IfModule>

For more information on the include file format for Apache, read our Modify Virtualhost Containers with Include Files documentation.