How to install and configure tomcat 8.5

September 18, 2022 / Servers, Hosting & Email

This guide explains the steps to install and configure Tomcat 8.5 with private instances on a cPanel server. The instructions are designed for users logged in via SSH as the root user or through WHM’s Terminal interface.

Note: Replace $username with the relevant cPanel account username in the provided commands.

  1. Install Tomcat RPM:
    1. Install Required Packages
      Run the following command to install the ea-tomcat85 and rng-tools packages:

      yum install ea-tomcat85 rng-tools -y
    2. Add Tomcat Support to a cPanel Account
      For each cPanel user requiring Tomcat, execute:

      /scripts/ea-tomcat85 add $username

      Verify Tomcat is enabled for the accounts with:

      /scripts/ea-tomcat85 list
  2. Install Ubic:
    Ubic manages the private Tomcat instance. Ensure the cPanel user has shell access and write permissions for /home/$username/.bashrc.

    1. Install Ubic
      Run the following commands:

      su - $username

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

      For CloudLinux Users
      Add Java to the CageFS mounts:

      cagefsctl --addrpm tzdata-java

      cagefsctl –force-update

    2. Verify Ubic Installation:
      Check if Ubic is running and Tomcat is enabled for the user:

      su - $username -s /bin/bash -c 'ubic status ea-tomcat85'
  3. Configure the Tomcat Environment:
    1. Configure Application Directory:
      Modify the <Host> section in the /home/$username/ea-tomcat85/conf/server.xml file. Add the following entry below the autoDeploy, deployOnStartup, and deployXML settings:

      <Context path="" docBase="webapps/ROOT" reloadable="true"/>
    2. Verify the Environment:
      1. Determine the HTTP port:egrep ‘Connector port.*HTTP’ /home/$username/ea-tomcat85/conf/server.xml
      2. Copy the test JSP file to the ROOT directory:sudo -u $username cp -avp /opt/cpanel/ea-tomcat85/test.jsp /home/$username/ea-tomcat85/webapps/ROOT/
      3. Restart the Tomcat instance:
        su - $username -s /bin/bash -c ‘ubic restart ea-tomcat85’

        Access the test JSP file at:

        http://yourserverip:$PORT/test.jsp

        You should see a page displaying:
        Test JSP Page: This is a page to check that .jsp support has been enabled.

  4. Configure ProxyPass for Apache
    1. Get the AJP Connector Port
      Retrieve the AJP port:egrep ‘Connector port.*AJP’ /home/$username/ea-tomcat85/conf/server.xml
    2. Create ProxyPass Include Files
      Create an Apache include file for both HTTP and HTTPS:/etc/apache2/conf.d/userdata/std/2_4/$username/$domain.tld/tomcatproxypass.confAdd the following content:

      <IfModule proxy_ajp_module>

      Proxypass “/” “ajp://127.0.0.1:$PORT/”

      </IfModule>

      Replace $PORT with the AJP port obtained earlier.

    3. Rebuild and Restart Apache
      Apply the configuration:/usr/local/cpanel/scripts/rebuildhttpdconf && /usr/local/cpanel/scripts/restartsrv_httpd
    4. Verify ProxyPass:
      Access the test JSP file at:

      http://yourdomain.tld/test.jsp

      You should see the Test JSP Page confirming the successful ProxyPass configuration.

  5. Deploy Your Application
    1. Copy your application files to the following directory:
      /home/$username/ea-tomcat85/webapps/ROOT/
    2. Your application will be accessible at:
      http://yourdomain.tld/

By following these steps, you can successfully install and configure Tomcat 8.5 with private instances on a cPanel server. If you encounter issues, feel free to contact support.

Spread the love