Tomcat Installation and Configuration in cPanel
In this tutorial we can check the Tomcat installation and configuration in cPanel
What is apache tomcat
Apache Tomcat is an open-source Java Servlet Container that is developed by Apache Software Foundation (ASP). It makes our Java applications run on a server. Apache tomcat is configured on the port 8080. Also, tomcat acts like a development server on your desktop to use for testing building applications that uses servlets/JSP or other Java based dynamic web technologies. EasyApache 4 does not support Tomcat. Tomcat installation is only applicable for the panel that uses EasyApache 3.
Working of Tomcat in cPanel
In cPanel EasyApache configures the tomcat webserver to listen on ports such as 80, 443, and 8009. If a client sends a request to port 80 or 443 the Apache webserver read the request and if the request is for tomcat service, then apache translates the request from HTTP to AJP protocol and sends to port 8009. Then Tomcat reads the request and sends the request to tomcat workers. They return the result of the request to the tomcat server and converts the result to the HTTP protocol and passes the request to the Apache web server. Finally, Apache sends the information to the client. If the client is sending request directly to 8080 then tomcat responds directly.
Installing Tomcat on cPanel server
To install tomcat selects a Tomcat option from shot option list area in WHM’s EasyApache 3 interface (Home >> Software >> EasyApache 3). You can also install tomcat on cPanel server by using /scripts/easyapache on the command line. After the installation, you need to enable Java Servlets for the account through WHM >> Account Functions >> Install Servlets. This option is only available after the complete installation of tomcat. Select the account in the Account Selection table and click the Install button. You can also enable the account by using /scripts/addservlets –domain=domain.com in command line. You can enable servlet for subdomain and addon domain by using the command above
Now you have successfully installed tomcat for your domain in cPanel.
Deploy Java Applications on Tomcat server
After installing tomcat and enabling the Servlets, user can deploy java application on their website by following the below steps:
1) Log into cPanel and navigate to ‘File Manager’.
2) Click on new Folder and enter any folder name.
3) Select your folder
4) Click upload >> choose file >> Browse the JAVA WAR file and click open.
5) Select the file name and click rename >> change the file extension to .war to .zip.
6) Select the .zip file and extract it.
7) Add the below code to .htaccess file in public_html.
SetEnv JK_WORKER_NAME ajp13
8) Access the java application with url : http://domain.com/newdirectory/javaapplication
You can also deploy the application using command line. You just upload the WAR file to public_html and unzip war file and add the below code to .htaccess file
SetEnv JK_WORKER_NAME ajp13
and save the changes.
To access the Tomcat Manager
You can access your tomcat server from http://domain.com:8080/manager
If you want to stop the tomcat from your cPanel server then you can remove it from WHM >>Service Configuration >> Service Manager.
You can remove all servlets by running this command: