Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Installation of Tomcat and adding JSP support for a domain on cpanel server  (Read 4139 times)

0 Members and 1 Guest are viewing this topic.

sajugovind

  • Guest
01. Installation of Tomcat and adding JSP support for a domain

a. Installation


To install Tomcat, select the Tomcat option in WHM’s EasyApache (Apache Update) or using “/scripts/easyapache” (without the quotes) in command line. The Tomcat selection is found in Step 5’s Apache Options area.

b. Adding servlet support

After Tomcat has been installed, use WHM > Account Functions > Install Servlets to add JSP and servlets to an account’s main domain. You can also do this using the following in shell:


Code: [Select]
/usr/local/cpanel/scripts/addservlets2 --domain=domain.comPlease replace domain.com with the domain name.

c. Subdomain servlet support

You would need to use command line for adding subdomain support for servlets as they do not automatically include that support and WHM does not have any option to add servlets to subdomains.

d. Addon domain servlet support

Addon domains will not work when added using command line if added by the addon domain name. The /usr/local/apache/conf/httpd.conf ServerName sub.domain.com line is what is used and it must match the Host name="sub.domain.com" line in /usr/local/jakarta/conf/server.xml file exactly, so addon domain support is added by installing servlets onto the subdomain associated with the addon domain:


Code: [Select]
/usr/local/cpanel/scripts/addservlets2 --domain=sub.domain.com

e. Removing servlets

To remove JSP and servlets, only command line is available via this command:

Code: [Select]
/usr/local/cpanel/scripts/remservlets --domain=domain.com

02. Structure of the JSP and servlets installation


Tomcat places files into /usr/local/jakarta/tomcat which is symlinked from /usr/local/jakarta/apache-tomcat-# where # is the Tomcat version that was installed by EasyApache.

Here are the various files and folders:

/usr/local/jakarta/tomcat/conf/server.xml - Tomcat configuration file
/usr/local/jakarta/tomcat/bin - folder with Tomcat binaries such as startup.sh and shutdown.sh scripts
/usr/local/jakarta/tomcat/logs - folder with Tomcat log files
/usr/local/jakarta/tomcat/work/Catalina - folder for domains with servlet support that houses extracted .war files and other JSP content


03. Versions of Tomcat and Java

To see the Tomcat and JVM versions and paths, you can run the following in command line:

Code: [Select]
/usr/local/jakarta/tomcat/bin/version.sh
It outputs information such as the following:

Code: [Select]
root@host [/usr/local/jakarta/tomcat/bin]# ./version.sh
Using CATALINA_BASE:   /usr/local/jakarta/tomcat
Using CATALINA_HOME:   /usr/local/jakarta/tomcat
Using CATALINA_TMPDIR: /usr/local/jakarta/tomcat/temp
Using JRE_HOME:        /usr/local/jdk
Using CLASSPATH:       /usr/local/jakarta/tomcat/bin/bootstrap.jar
Server version: Apache Tomcat/5.5.35
Server built:   Jan 6 2012 11:20:07
Server number:  5.5.35.0
OS Name:        Linux
OS Version:     2.6.18-274.7.1.el5.028stab095.1
Architecture:   amd64
JVM Version:    1.6.0_29-b11
JVM Vendor:     Sun Microsystems Inc.

If you only want to get the Java version, you can run:

Code: [Select]
java -version
It will show something like the following:

Code: [Select]
root@host [/usr/local/jakarta/tomcat/bin]# java -version
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode

04. Logs

a. Tomcat logs

The Tomcat log files are at /usr/local/jakarta/tomcat/logs location. They are the following:

catalina.err - The Tomcat error log
catalina.out - The Tomcat process log


b. mod_jk logs and runtime file

The mod_jk error and warning log file is at /usr/local/apache/logs/mod_jk.log location.

Of note, the jk-runtime-status.pid# and jk-runtime-status.pid#.lock files are also located in /usr/local/apache/logs directory.

05. Processes and Restarting Tomcat Properly

When Tomcat is installed onto a machine, the following type of processes will show:

Code: [Select]
root 20184 0.0 0.0 10432 352 ? Ss 01:39 0:00 jsvc.exec -user tomcat -cp ./bootstrap.jar -Djava.endorsed.dirs=../common/endorsed -outfile ../logs/catalina.out -errfile ../logs/catalina.err -verbose org.apache.catalina.startup.Bootstrap start

tomcat 20185 0.1 3.6 2789484 76012 ? Sl 01:39 0:05 jsvc.exec -user tomcat -cp ./bootstrap.jar -Djava.endorsed.dirs=../common/endorsed -outfile ../logs/catalina.out -errfile ../logs/catalina.err -verbose org.apache.catalina.startup.Bootstrap start

If Tomcat is restarted manually without using our restart script at “/usr/local/cpanel/scripts/restartsrv_tomcat”, this type of process will show up instead:

Code: [Select]
root 22013 49.1 2.7 1732028 57464 pts/0 Sl 02:48 0:02 /usr/local/jdk/bin/java -Djava.util.logging.config.file=/usr/local/jakarta/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/jakarta/tomcat/common/endorsed -classpath /usr/local/jakarta/tomcat/bin/bootstrap.jar -Dcatalina.base=/usr/local/jakarta/tomcat -Dcatalina.home=/usr/local/jakarta/tomcat -Djava.io.tmpdir=/usr/local/jakarta/tomcat/temp org.apache.catalina.startup.Bootstrap start
This is done by issuing the following command:


Code: [Select]
[b]/usr/local/jakarta/tomcat/bin/startup.sh[/b]
If you restart Tomcat using our service, we will not kill this process. The process needs to be killed manually (with “kill PID#” where PID# is the process number) before restarting our own Tomcat instance. If it isn’t, then Tomcat won’t function.

Of note, you can also restart Tomcat by calling “/usr/sbin/starttomcat” script, which is what our script calls.

06. Tomcat manager

a. Tomcat manager location

The Tomcat manager is at http://server.domain.com:8080/manager/html location (where server.domain.com is the machine’s hostname). Any domain on the server can also call this location via the same path.

b. Available options

Applications are listed in the manager with the ability to start, stop, reload and undeploy them there. War files can also be uploaded and deployed in the manager.

A Server Status section exists in Tomcat manager at http://server.domain.com:8080/manager/status

c. Authenticating

The username and password for accessing Tomcat manager is stored in /usr/local/jakarta/tomcat/conf/tomcat-users.xml file such as the following:
Code: [Select]
<tomcat-users>
  <user name="tomcat" password="tomcat" roles="tomcat" />
  <user name="role1"  password="tomcat" roles="role1"  />
  <user name="both"   password="tomcat" roles="tomcat,role1" />
  <user name="root" password="dK08U9PbCcU1" roles="admin,manager" />
</tomcat-users>

The manager is specifically the root user.

d. Giving another user access

Another user can be given access by adding an additional user line such as this example where the endar user is being added:

Code: [Select]
<tomcat-users>
  <user name="tomcat" password="tomcat" roles="tomcat" />
  <user name="role1"  password="tomcat" roles="role1"  />
  <user name="both"   password="tomcat" roles="tomcat,role1" />
  <user name="root" password="dK08U9PbCcU1" roles="admin,manager" />
  <user name="endar" password="h@ppyt1m3" roles="admin,manager" />
</tomcat-users>

Tomcat would need to be restarted after making this change:

Code: [Select]
/scripts/restartsrv_tomcat
07. War files

a. Description

War files are archives containing the full JSP and servlet application. They are automatically extracted by Tomcat into /usr/local/jakarta/tomcat/work/Catalina/domain.com location (where domain.com is the domain name for the site) by the name of the .war file. For example, if you have hello.war file, then the extracted folder application will be /usr/local/jakarta/tomcat/work/Catalina/domain.com/hello

b. Tomcat versus Apache

When war files extract, they extract only in the Tomcat folder and not the user’s /home/username/public_html folder. Because they aren’t extracted there, Apache does not recognize the folder and the application will then only load at http://domain.com:8080/hello (using our prior example) and not at http://domain.com/hello

There has been some confusion that these are not automatically set to extract using our default entry in /usr/local/jakarta/tomcat/conf/server.xml but this is not the case. Our default setup does have these extract into /usr/local/jakarta/tomcat/work/Catalina/domain.com path.

Conversely, they will not show up on Apache under port 80 by default. Revising the server.xml also does not work for these to auto extract nor is that even necessary to do. The way to add servlet support and to get all extracted war files showing up under Apache is by adding these two lines to /home/username/public_html/.htaccess file:


Code: [Select]
SetHandler jakarta-servlet
SetEnv JK_WORKER_NAME ajp13


I did this on my domain after adding sample.war to /home/endar/public_html (which then only extracted into /usr/local/jakarta/tomcat/work/Catalina/endar.org/sample folder), and after adding the lines I can access both Sample "Hello, World" Application and Sample "Hello, World" Application urls. That’s all it takes to get war files showing up under Apache.

The above lines also work for any servlet mapping where pages aren’t showing up in a browser with 404 errors for those pages even though the pages work when using the 8080 url.

c. war file testing

If war files appear not to be working, you can obtain a test war file at http://tomcat.apache.org/tomcat-5.5-...ple/sample.war and wget it to the account for deployment:

Code: [Select]
cd /home/username/public_html
wget http://tomcat.apache.org/tomcat-5.5-doc/appdev/sample/sample.war
chown username:username sample.war

At that point, try to load the http://domain.com:8080/sample url in a browser. If it works, then war files are working regularly.

08. Testing

To test if a domain has JSP working, there is a default test page that should be installed when servlet support is originally added to the domain or subdomain. The test page should look like the following on the backend for the file contents:

Code: [Select]
<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 requestwe 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>

The front end would look like the following in a browser at http://domain.com/jsptest.jsp path:

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 requestwe are
currently processing.
Code: [Select]
Request Method: GET
Servlet Path: /jsptest.jsp

If it does not look like this, then a different test page is being used. As such, copy the sample jsptest.jsp page at /usr/local/jakarta/apache-tomcat-5.5.35/samples/jsptest.jsp to the user’s account and check if it works:


Code: [Select]
cp /usr/local/jakarta/apache-tomcat-5.5.35/samples/jsptest.jsp /home/username/public_html
chown username:username /home/username/public_html/jsptest.jsp
/scripts/restartsrv_tomcat

Please replace username with the cPanel username above.

While Tomcat doesn’t really need to be restarted in this instance, doing so ensures that the account reloads. If the test page works and other pages still aren’t working, it is would be a coding issue.

Thank you.........