This tutorial drives through the method of installing Tomcat 8.5 with private instances. Here, all instructions are implemented as though you were logged into the server through SSH as the root user, or are working on WHM’s Terminal (WHM > Server Configuration > Terminal).
In the below examples, $username specifies the username linked with the individual cPanel account.
Steps for Installing Tomcat
1. To Install the Tomcat RPM
Firstly, we need to install the ea-tomcat85 and rng-tools packages.
To act, use the below command-
yum install ea-tomcat85 rng-tools -y
2. Now, Add Tomcat Support to an account.
Next, we need to add support for Tomcat to the account(s) that will require it. Use the below command, replicating for each user that requires Tomcat:
/scripts/ea-tomcat85 add $username
Once the above action is complete, you can validate that Tomcat is enabled for the accounts
To Install Ubic
1. Installation Process
Installation of Ubic for any given cPanel user is pretty reliable forward. It needs the cPanel user to have shell access to the server including the write permissions to the users /home/$username/.bashrc file. The below command can be pasted into the shell/terminal while logged with root access after replacing the $username with the right username.
su - $username
echo "export PATH=$(dirname $(readlink /usr/local/cpanel/3rdparty/bin/perl)):$PATH" >> /home/$username/.bashrc
a. CloudLinux Considerations
If you are applying CloudLinux, then you will also need to run the below commands (from the root level) to add Java to the CageFS mounts:
cagefsctl --addrpm tzdata-java cagefsctl --force-update
Once installed, you can test that Ubic is running and that Tomcat is enabled for the user with this command (from the root level):
su - $username -s /bin/bash -c 'ubic status ea-tomcat85'
Tomcat Environment Configuration
Tomcat environment configuration is the most complex part of this process. The steps explained below can be applied to configure the environment correctly. Please be notified that the ports recorded below are just examples, and your particular ports may vary.
1. Application Directory Configuration
To enable the ROOT webapp directory for testing, add the following entry to the <Host> section in the /home/$username/ea-tomcat85/conf/server.xml file.
This section starts with the deploy options, so this can be set below the line containing the autoDeploy, deployOnStartup, and deployXML settings.
2. Verify the environment
To verify that the environment is working, we suggest you copy our test.jsp and try to call it directly, before performing any modifications that may affect Apache’s configuration.
You will need to know the port to test again. It can be obtained using the below command:
egrep 'Connector port.*HTTP' /home/$username/ea-tomcat85/conf/server.xml
To copy the test script, use the following command:
sudo -u $username cp -avp /opt/cpanel/ea-tomcat85/test.jsp /home/$username/ea-tomcat85/webapps/ROOT/
Once completed, you need to restart the Private Tomcat Instance for the user:
su - $username -s /bin/bash -c 'ubic restart ea-tomcat85'
To confirm test.jsp is working, access “http://yourserverip:$PORT/test.jsp” with your preferred method, where $PORT is the port obtained earlier. You must receive a page containing the following:
Test JSP Page
This is a page to check that .jsp support has been enabled.
3. Configure Proxypass
Initially, you need to get the AJP connector port so that you can correctly configure the ProxyPass directive. This command will restore the port info:
egrep 'Connector port.*AJP' /home/$username/ea-tomcat85/conf/server.xml
Once you have obtained the port, then you can create a ProxyPass Apache include file. Remember to complete this action twice. Onetime for http (std) and another for https (ssl). Both use the same approach as our Apache VHost Includes. The path includes for http (std):
And the file would look similar to this:
<IfModule proxy_ajp_module> Proxypass "/" "ajp://127.0.0.1:$PORT/" </IfModule>
Where $PORT is the port value recovered from the previous command.
After creating the include files you need to rebuild the Apache configuration and restart the service. The set of commands recorded below will accomplish this quickly:
/usr/local/cpanel/scripts/rebuildhttpdconf && /usr/local/cpanel/scripts/restartsrv_httpd
Lastly, verify that the ProxyPass include is running by loading up “http://yourdomain.tld/test.jsp” in your preferred browser. As before, you should get the resulting output:
Test JSP Page
This is a page to check that .jsp support has been enabled successfully.
Installing your site
Once you have made it this far successfully you’re now ready to install your application. Just copy the application files into /home/$username/ea-tomcat85/webapps/ROOT/ and your application will load at yourdomain.tld/.