Apache Tomcat is a powerful, Java-based web application server that provides support for Java Servlet and JSP technologies. It enables the deployment and execution of WAR (Web Application Archive) files and includes a self-contained HTTP server for seamless web hosting.
Key Tomcat Configuration Paths:
- CATALINA_HOME:
/usr/local/jakarta/tomcat - CATALINA_BASE:
/usr/local/jakarta/tomcat - JAVA_HOME (JDK Path):
/usr/local/jdk
Tomcat Log Files:
Monitor logs using the following command:
tail -f /usr/local/jakarta/tomcat/logs/catalina.out | egrep domain.com
- Logs are stored in:
/usr/local/jakarta/tomcat/logs/catalina.out
Deploying WAR Files in Tomcat
By default, WAR files are automatically deployed during startup. This behavior can be disabled per host using the deployOnStartup attribute.
- Extract a WAR file using:
unzip example.war
Directory Structure After Extraction:
META-INF/
META-INF/MANIFEST.MF
helloworld.jsp
WEB-INF/
WEB-INF/web.xml
index.html
WAR files are scanned every 10 seconds in the appBase directory.
Deployed applications reside in:
/usr/local/jakarta/tomcat/work/Catalina/example.com/war_file_name/
Tomcat Configuration Files
Tomcat’s configurations are primarily stored in XML format:
- Main Configuration Directory:
/usr/local/jakarta/tomcat/conf/ - Apache HTTP Server Configuration:
/usr/local/apache/conf/httpd.conf - mod_jk Configuration:
/usr/local/apache/conf/jk.conf
mod_jk Setup for Apache-Tomcat Integration
The mod_jk module enables communication between Apache HTTP Server and Tomcat.
Example Configuration for mod_jk:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /usr/local/jakarta/tomcat/conf/workers.properties
JkLogFile /usr/local/apache/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat “[%a %b %d %H:%M:%S %Y]”
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat “%w %V %T”
JkMount Configuration (Mapping Requests to Tomcat Workers):
<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
</IfModule>
Configuration files for individual sites are located in:
/usr/local/apache/conf/userdata/std/1/tom/tomcat.com/cp_jkmount.conf
WAR Deployment in cPanel Using mod_jk
To deploy a WAR file in a cPanel account:
- Upload the WAR file to the public_html directory of the user’s account.
- Configure mod_jk to recognize the application.
- Add a JkMount directive to the site’s include file and restart Apache HTTP Server (
httpd).
Example cPanel WAR Deployment Configuration:
<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
JkMount /appname/* ajp13
</IfModule>
Useful Tomcat Resources:
- Apache Tomcat Project Page: http://tomcat.apache.org/
- JDK Download: http://www.oracle.com/technetwork/java/javase/downloads/index.html
- Tomcat Configuration Tips: http://oreilly.com/java/archive/tomcat-tips.html