Introduction
NOTE: cPanel & WHM does not support Tomcat on servers that run CentOS 8.
The following guide shows how to set up a test application with Tomcat 8 and EasyApache. This is an excellent way to get an understanding of the basic concepts for setting up a Tomcat application and verify that Tomcat works on your cPanel server.
The entire procedure is done via SSH as the root user.
These commands can be copied and pasted directly as they are presented if you are simply creating a test account to verify that Tomcat is working on the server. You may also replace the example username and domain with your own to set up a new account with a working test application to start off with.
Procedure
1. Ensure that the required packages are installed:
yum install ea-tomcat85 rng-tools -y
2. Create a test account that you can use temporarily to verify that Tomcat is working:
whmapi1 createacct username=tcattest domain=tcat.tld password=$(openssl rand -base64 12)
3. Add Tomcat to the user:
/scripts/ea-tomcat85 add tcattest
4. Add access to the ubic utility for the user's shell:
echo "export PATH=$(dirname $(readlink /usr/local/cpanel/3rdparty/bin/perl)):$PATH" >> /home/tcattest/.bashrc
5. If the server is using Cloudlinux, you will also need to run the following commands to add Java to the Cagefs mount.
cagefsctl --addrpm tzdata-java
cagefsctl --force-update
6. Add the required context within the <Host ... > element of the server.xml configuration:
/home/tcattest/ea-tomcat85/conf/server.xml
<Context path="/" docBase="/home/tcattest/ea-tomcat85/webapps/ROOT/">
</Context>
The result should look like the following within the server.xml file:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="false" deployOnStartup="false" deployXML="false">
<Context path="/" docBase="/home/tcattest/ea-tomcat85/webapps/ROOT/">
</Context>
7. Copy the test application into place:
sudo -u tcattest cp -avp /opt/cpanel/ea-tomcat85/test.jsp /home/tcattest/ea-tomcat85/webapps/ROOT/
8. Restart the Tomcat Private Instance:
su - tcattest -s /bin/bash -c 'ubic restart ea-tomcat85'
9. Locate the connector port:
egrep 'Connector port.*HTTP' /home/tcattest/ea-tomcat85/conf/server.xml
10. Use the port found from the command above along with your server's public IP to verify that the test application is working properly:
lynx --dump http://x.x.x.x:CONNECTORPORTHERE/test.jsp
11. Locate the AJP port:
egrep 'Connector port.*AJP' /home/tcattest/ea-tomcat85/conf/server.xml
12. Setup a ProxyPass configuration so that Apache can serve the application.
A more detailed guide can be found below that includes an example for port 443 (https):
/etc/apache2/conf.d/userdata/std/2_4/tcattest/tcat.tld/custom.conf
<IfModule proxy_ajp_module>
ProxyPass "/cptest" "ajp://127.0.0.1:AJPPORTHERE/"
</IfModule>
13. Rebuild the Apache configuration and restart Apache:
/scripts/rebuildhttpdconf && /scripts/restartsrv_httpd
14. Update the hosts file with your fake/test domain if needed so that the final test works.
/etc/hosts
15. Test with the domain to verify that the ProxyPass configuration works:
lynx --dump http://tcat.tld/test.jsp
Comments
0 comments
Article is closed for comments.