Tomcat Dummies for Cpanel Server

How to enable tomcat support for an account created under Cpanel Server?

Quite simple. If you’re a server admin, Login to WHM and search for “Install Servlets” option. Select the domain name and click on Install.

Now, this feature will make the required configuration entires in Tomcat configuration file i.e /usr/local/jakarta/tomcat/conf/server.xml

It looks as follows :

<Host name=”domainname.com” appBase=”/home/domainna/public_html”>
<Context path=”" reloadable=”true”
docBase=”/home/domainna/public_html” debug=”0″/>
<Context path=”/manager” debug=”0″ privileged=”true”
docBase=”/usr/local/jakarta/tomcat/server/webapps/manager”>
</Context>
<Alias>www.domainname.com</Alias>

Along with this few more entries needs to be added to your servers configuration file related to apache mod_jk module.

Following IfModule section is added inside the virtual host entry of the domain (here it is domainname.com please check server.xml entry which I mentioned earlier)

<IfModule mod_jk.c>
JkMount /*.do ajp13
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /manager/* ajp13
</IfModule>

For the above lines to work with Apache, you got to be sure that mod_jk apache module is installed and loaded into Apache.

Search for following lines in httpd.conf to confirm the same :

LoadModule jk_module libexec/mod_jk.so
AddModule mod_jk.c

Now, you’re ready to go ahead and restart apache and tomcat (PS: If you’re installing servlet from WHM, you need not restart tomcat)

You might notice that installing servlet via WHM added an a folder called WEB-INF folder inside the document root of the domain (/home/domainna/public_html in the above example). This folder can be used to organize your servlet classes and lib files. Your domains web.xml will also go into WEB-INF.

Now, lets put a test jsp file called jsptest.jsp with the following code :

<html><head><title>Test JSP page</title></head><body bgcolor=white>

<table border=”0″><tr><td><h1>Sample Application JSP Page</h1>
This is the output of a JSP page that is part of the Hello, World application.
It displays several useful values from the request we are currently
processing.</td></tr>
</table>

<table border=”0″ border=”100%”><tr>
<th align=”right”>Request Method:</th>
<td align=”left”><%= request.getMethod() %></td></tr><tr>
<th align=”right”>Servlet Path:</th>
<td align=”left”><%=
request.getServletPath() %></td></tr></table></body></html>

Save the file and browse this jsp file from the browser now.

Ex: http://domainname.com/jsptest.jsp

Are you greated with the following message ?

Sample Application JSP Page
This is the output of a JSP page that is part of the Hello, World application.
It displays several useful values from the request we are currently processing.
Request Method: GET
Servlet Path: /jsptest.jsp

Kewl! Congratulations. Your Jsp file is working now.

Now go ahead and update your client.

Leave a comment

11 Comments.

  1. Awesome!

    Its really helpful.

  2. Hi

    thankyou very much for this helpful info
    but i have question about java classess

    the jsp files work fine and your test jsp example work fine also

    BUT

    if jsp file use any java class the page cannot load it
    get errors

    please if you have any idea about use java class with jsp in Cpanel

    please help

    thanks

  3. Hi Hussain,

    Put the java class files into WEB-INF/lib folder. It should work without any issues.

  4. Dude, thanks for this, reaaaaaaaaaaaaaallly helped me out =)

  5. Hi,
    Can you please tell how I can deploy a war file on tomcat using cPanel?

    Any links /pointers welcome.
    Thanks,Ed

  6. There is no way you can directly deploy war files on a cPanel server. You will have to get the admin doing that for you. But normally cPanel hosting service providers won’t let you use war files.

  7. Hi,

    How can i access the tomcat page using temp URL?
    http://74.40.81.27/~/jsp/HFM/admin/login.jsp

    Is this is possible?

  8. Math, If you’re on cpanel server enable userbase dir to access it via http:///~username/

  9. It’s not clear in the tut on where I place

    JkMount /*.do ajp13
    JkMount /*.jsp ajp13
    JkMount /servlet/* ajp13
    JkMount /servlets/* ajp13
    JkMount /manager/* ajp13

    and adding Addmodule to httpd.conf stops aphache from starting

  10. Hi all,

    If anybody is having problems when a jsp references a class switch you appBass to webapps

    Example Before:-

    Example After:-

    I don’t know why that fixes it,but I’ve spent all day trying to get my app working despite my WEB-INF in public_html being correct.

  11. Yves,

    Following code gets inside your domains virtual host entry in httpd.conf


    JkMount /*.do ajp13
    JkMount /*.jsp ajp13
    JkMount /servlet/* ajp13
    JkMount /servlets/* ajp13
    JkMount /manager/* ajp13

Leave a Reply


[ Ctrl + Enter ]

Comment moderation is enabled. Your comment may take some time to appear.