This tutorial guides you through the process of installing Tomcat 8.5 with private instances on a cPanel server. All instructions assume you are logged in via SSH as root or using WHM's Terminal. In the examples below, $username represents the username associated with the specific cPanel account (e.g., /home/example123/.bashrc).

How to Install and Configure Tomcat 8.5

  1. Step 1: Install the Tomcat RPM

    Begin by installing the ea-tomcat85 and rng-tools packages:

    yum install ea-tomcat85 rng-tools -y
  2. Step 2: Add Tomcat Support to an Account

    Add Tomcat support to the account(s) that need it. Execute the following command for each user requiring Tomcat:

    /scripts/ea-tomcat85 add $username

    Tomcat add command output

    After completing this step, verify that Tomcat has been enabled for the accounts:

    /scripts/ea-tomcat85 list

    Tomcat list command output

  3. Step 3: Install Ubic

    The installation of Ubic for any given cPanel user requires the cPanel user to have shell access to the server, including write permissions to the /home/$username/.bashrc file. Use the following commands in the shell/terminal while logged in with root access, replacing $username with the correct username:

    su - $username
    echo "export PATH=$(dirname $(readlink /usr/local/cpanel/3rdparty/bin/perl)):$PATH" >> /home/$username/.bashrc

    Ubic installation command

    For CloudLinux users: If you are using CloudLinux, execute the following commands (from the root level) to add Java to the CageFS mounts:

    cagefsctl --addrpm tzdata-java
    cagefsctl --force-update
  4. Step 4: Verify Ubic Installation

    After installation, confirm that Ubic is running and Tomcat is enabled for the user with the following command (from the root level):

    su - $username -s /bin/bash -c 'ubic status ea-tomcat85'

    Ubic status check

  5. Step 5: Configure the Application Directory

    To enable the ROOT webapp directory for testing, add an entry to the section in the /home/$username/ea-tomcat85/conf/server.xml file. This section begins with the deploy options, so it can be placed below the line containing the autoDeploy, deployOnStartup, and deployXML settings.

  6. Step 6: Verify the Environment

    To ensure that the environment is functioning correctly, copy the test JSP file and attempt to call it directly before making any modifications that may impact Apache's configuration.

    First, identify the port for testing using the following command:

    egrep 'Connector port.*HTTP' /home/$username/ea-tomcat85/conf/server.xml

    Copy the test script:

    sudo -u $username cp -avp /opt/cpanel/ea-tomcat85/test.jsp /home/$username/ea-tomcat85/webapps/ROOT/

    Reboot the user's Private Tomcat Instance:

    su - $username -s /bin/bash -c 'ubic restart ea-tomcat85'

    To verify that test.jsp is operational, access http://yourserverip:$PORT/test.jsp in your browser, where $PORT is the previously obtained port. You should see a page with the following content:

    Test JSP Page
    This is a page to check that .jsp support has been enabled.

  7. Step 7: Configure ProxyPass

    To properly configure the ProxyPass directive, start by obtaining the AJP connector port:

    egrep 'Connector port.*AJP' /home/$username/ea-tomcat85/conf/server.xml

    AJP connector port

    Once you have obtained the port, create a ProxyPass Apache include file. Perform this action twice, once for http (std) and another for https (ssl). The path for http (std) includes:

    /etc/apache2/conf.d/userdata/std/2_4/$username/$domain.tld/tomcatproxypass.conf

    The content of the file should resemble the following:

    
      ProxyPass "/" "ajp://127.0.0.1:$PORT/"
    

    Where $PORT is the port value retrieved from the previous command.

    After creating the include files, rebuild the Apache configuration and restart the service:

    /usr/local/cpanel/scripts/rebuildhttpdconf && /usr/local/cpanel/scripts/restartsrv_httpd

    Finally, confirm that the ProxyPass include is functioning by loading http://yourdomain.tld/test.jsp in your browser. You should see:

    Test JSP Page
    This page verifies the successful enabling of .jsp support.

  8. Step 8: Install Your Site

    If you have reached this point successfully, you are now ready to install your application. Simply copy the application files into /home/$username/ea-tomcat85/webapps/ROOT/, and your application will be accessible at yourdomain.tld/.