Getting Tomcat and Apache to talk
Nov 21st, 2005 by Karen
I’ve been working on getting the developer version of Coldfusion to run on my Mac using Tomcat and Apache as the webserver. I posted before on how to set up Coldfusion with Tomcat. However, this post discusses taking things one step further and getting Apache to be the main webserver and route Coldfusion and Java Server Page requests to Tomcat.
Here’s the idea. I want a test website that is capable of running plain HTML pages as well as JSP, and Coldfusion pages. I don’t want to have to go to a seperate port to run my JSP and Coldfusion pages and ideally I’d like to be able to store all my pages in the same directory. So how do I do that. Well first I need to get Apache to route Coldfusion and JSP requests to Tomcat. To do that I need to do that following.
- Add an Apache module called mod_jk
- Create a “worker” in Tomcat to handle my Coldfusion and JSP request
- Alter my Apache httpd.conf file to direct requests for Coldfusion and JSP pages to Tomcat
Adding mod_jk
There are two different ways you can add mod_jk into Apache. The first is download the mod_jk binary for OSx from the Apache Jakarta Project. However, if you do this and follow the installation instructions, you will likely get an error message like “this module might crash under EAPI!” when you restart Apache. To avoid getting this error message you need to download the source for m0d_jk and compile it with EAPI. Then load it into Apache.
- Download the source for mod_jk (version 1.2.15) from The Apache Jakarta Tomcat Connector page
Make sure you put it someplace useful like your Home directory (/Users/username). - Extract the file using Stuff It or from the command line using the unzip command. This will create a jakarta-tomcat-connectors-jk-1.2.5-macosx-apache-1.3.28 folder with many other folders in it.
- Go into the /Users/username/jakarta-tomcat-connectors-jk-1.2.5-macosx-apache-1.3.28/jk/native and run configure with the following switches ( –with-apxs=/usr/sbin/apxs –enable-EAPI). This looks like
./configure --with-apxs=/usr/sbin/apxs --enable-EAPI
Note: You need to have the Xcode Tools installed to do this. Otherwise you will get an error message saying that the configure program can’t find a C compiler. If you need to you can install Xcode Tools from your original Mac OS X install disc. - Go to the apache-1.3 directory and run Make.apxs
cd apache-1.3 make -f Makefile.apxs
This will create you a mod_jk.so file in your apache-1.3 directory.
- Copy the mod_jk.so file from /Users/username/jakarta-tomcat-connectors-jk-1.2.5-macosx-apache-1.3.28/jk/native/apache-1.3 to the /usr/libexec/httpd folder
- In the LoadModules section of your httpd.conf file, add the following line
LoadModule jk_module libexec/httpd/mod_jk.so
In the AddModules section of your httpd.conf file add this line
AddModule mod_jk.c
- Stop Apache
- Start Apache and make sure you don’t get any error message on startup
Creating a worker in Tomcat
In order to allow Tomcat to receive pages from Apache and process them we need to create a worker in Tomcat.
- Go to the /Library/Tomcat/apache-tomcat-5.5.12/conf and create a file named worker.properties
- Put the following lines into the worker.properties file
# Setup for Mac OS X workers.tomcat_home=/Library/Tomcat/apache-tomcat-5.5.12 workers.java_home=/Library/Java/Home worker.list=workername worker.workername.type=ajp13 worker.workername.host=computername worker.workername.port=8009 worker.workername.socket_keepalive=1
- Save the worker file
Making adjustments to my Apache httpd.conf file
Once you have created the worker file for Tomcat you need to add settings to the Apache httpd.conf file in order to redirect requests for JSP and Coldfusion page to Tomcat.
- Open up the httpd.conf file from /etc/httpd
- Add the following lines at the bottom of the conf file.
<IfModule mod_jk.c> Alias /directory_where_CFM_JSP_pageslive "/Library/Tomcat/apache-tomcat-5.5.12/webapps/directory_where_CFM_JSP_pageslive" JkMount /directory_where_CFM_JSP_pageslive/* workername JkWorkersFile /Library/Tomcat/apache-tomcat-5.5.12/conf/workers.properties JkLogFile /Library/Tomcat/apache-tomcat-5.5.12/logs/mod_jk.log JkLogLevel trace <Location "/*/WEB-INF/*"> AllowOverride None deny from all </Location> </IFModule>
- Stop Apache
- Start Apache and make sure no errors occur
- Go to http://your.webaddress.net/directory_where_CFM_JSP_pageslive and check to make sure your JSP and Coldfusion pages work
If you want a slightly more in depth explanation of these configurations check out this post or the mod_jk documentation.

