HostedDB - Dedicated UNIX Servers

apache 2.0 | tomcat 4 | RH 7.2 HOWTO

apache 2.0.40 / tomcat 4.0.4 / mod_jk

(last updated 09/05/2002)

This is for a RH Linux installation, version 7.2. Output of `uname -a`:

Linux localhost 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown

ASSUMPTION #1: you have the JDK installed, and you have an environment variable named "JAVA_HOME" set to the location of your JDK installation. For example, in this case, the JDK is installed in /usr/java/j2sdk1.4.0_01, and that is the value of JAVA_HOME. If you don't have the JDK installed, grab it from here: http://java.sun.com/j2se/ and follow the installation instructions that came with the package you downloaded.

ASSUMPTION #2: you have ant installed, and you have an environment variable called ANT_HOME set to ant's location. If you don't have ant installed, install it. You can get ant from here: http://jakarta.apache.org/builds/jakarta-ant/release/v1.5/bin/. The manual for ant is here: http://jakarta.apache.org/ant/manual/index.html

This document will show how to connect apache 2.0 and tomcat 4.0.4 such that tomcat's examples, found at http://localhost:8080/examples, will execute properly for requests on port 80: http://localhost/examples. This document does not describe configuration for apache or tomcat virtual hosts.

On to apache + tomcat + mod_jk:


1) create a directory called /usr/local/packages (or any other directory you prefer, I tend to put things in /usr/local)

2) grab apache 2.0.40 (httpd-2.0.40.tar.gz) from a mirror, put it in /usr/local/packages

3) grab jakarta-tomcat-4.0.4.tar.gz from http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0.4/bin/, put it in /usr/local/packages. This is a binary install of tomcat 4.0.4, not an RPM (I typically don't trust RPMs).

4) grab jakarta-tomcat-connectors-4.0.4-src.tar.gz from http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0.4/src/, put it in /usr/local/packages.

5) install apache from source

First, expand the package into a suitable location (ex: /usr/local/apache2). Change directories to that location when the expanding is done.

a) run configure: ./configure --prefix=/usr/local/apache2 --enable-module=so
b) run make: make
c) run make install: make install
d) quickly verify apache starts: /usr/local/apache2/bin/apachectl start (ignore errors about ServerName)
e) check for apache start page at http://ip_address
f) shutdown apache: /usr/local/apache2/bin/apachectl stop
g) copy http.conf file before making changes: cp -p /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.orig
h) modify httpd.conf: change ServerName, port, etc. as needed.
i) verify apache starts (see 5d)
j) shutdown apache (see 5f)

6) install tomcat from binary (not RPM)

a) copy the package downloaded in step 3 to /usr/local/
b) expand the package: tar xvzf jakarta-tomcat-4.0.4.tar.gz. This will leave you with /usr/local/jakarta-tomcat-4.0.4. Delete the compressed package from /usr/local, you don't need it anymore (leave a copy in /usr/local/packages just in case)
c) add a symlink for admin purposes: cd /usr/local; ln -s jakarta-tomcat-4.0.4 tomcat. This leaves you with /usr/local/tomcat pointing to /usr/local/jakarta-tomcat-4.0.4.
d) make sure you have an environment variable named CATALINA_HOME set to the location of tomcat. In this case, CATALINA_HOME = /usr/local/jakarta-tomcat-4.0.4
e) startup tomcat: cd $CATALINA_HOME/bin; ./startup.sh
f) verify tomcat is running by going to http://ip_address:8080/examples and checking for no errors in both the JSP and servlet sections
g) assuming verified tomcat, shutdown tomcat in preparation for connecting tomcat to apache: ./shutdown.sh

At this point, you should have a working apache installation serving content on port 80, and a working tomcat installation serving content on port 8080 (the tomcat examples included with the tomcat installation work).

The Connector

To connect the two, you need a connector. As of 09/05/2002 there are 3 to choose from: mod_jk (AJP13), mod_webapp (WARP), and mod_jk2. Mod_webapp has some limitations (no differentiation between static and dynamic content so no use for apache), and mod_jk2 is pretty new, so we will use mod_jk since it has been around awhile and is stable.

1) First, realize that the connector projects are a little messy. It's going to take a bit of hacking around to get them to build. It can be done.

2) expand the connectors package to some location (such as /usr/local/packages/jakarta-tomcat-connectors-4.0.4-src)

2A) At this point, you have two build options: ant, or configure (the traditional ./configure method). Which you use is up to you, they are both detailed below. Pick one. I prefer ./configure.

NOTE: for the rest of this HOWTO, "CONNECTOR_HOME" = wherever you unpacked jakarta-tomcat-connectors-4.0.4-src.tar.gz, such as /usr/local/jakarta-tomcat-connectors-4.0.4-src/.

ant./configure
a) cd to CONNECTOR_HOME/jk.

b) check README.txt.

c) copy build.properties.sample to build.properties

d) edit build.properties. Set tomcat40.home = whatever CATALINA_HOME is. Do the same for tomcat41.home. Make the entry for tomcat33.home empty/blank. Change apache13.home to the location of apache 2.0.40 (like /usr/local/apache2). Set apache2.home to the same value as apache13.home.

e) run ant: $ANT_HOME/bin/ant build-jk. You will probably see an error message that says something about being unable to copy tomcat-coyote.jar. If your build with ant is successful (you see a message that says "BUILD SUCCESSFUL"), you're all set (continue with step F). If you do see the error about tomcat-coyote.jar (or one about tomcat-util.jar), do the following:

  • cd to CONNECTOR_HOME/coyote
  • run ant. ignore error messages...all you want to do is create a directory structure which ant will do for you even though it fails
  • cd to CONNECTOR_HOME/util
  • run ant again. ignore error messages...all you want to do is create a directory structure which ant will do for you even though it fails
  • find tomcat-coyote.jar on your system. It should be in CATALINA_HOME/server/lib/. copy it to CONNECTOR_HOME/coyote/build/lib/.
  • find tomcat-util.jar on your system. It should also be in CATALINA_HOME/server/lib. copy it to CONNECTOR_HOME/util/build/lib/.
  • cd back to CONNECTOR_HOME/jk. Run ant again. At this point, you should see a message that says "BUILD SUCCESSFUL". If you don't, reveiw any error messages and see if there is something out of place, such as a path, etc. Continue until you can run ant in CONNECTOR_HOME/jk and get a "Build Successful" message.

This should leave you with CONNECTOR_HOME/jk/build/lib/jkconfig.jar and jkshm.jar, as well as CONNECTOR_HOME/lib/commons-logging.jar. (need confirmation that this step is even necessary...the docs say "yes", but those jar files aren't used anywhere)

f) Build the mod_jk.so library for apache.

  • add a symlink for apxs (included with apache): cd to /usr/sbin; ln -s /path/to/apache2/bin/apxs apxs
  • cd to CONNECTOR_HOME/jk/native/apache-1.3
  • copy Makefile.linux to Makefile
  • run make: make
  • you should end up with a mod_jk.so file in CONNECTOR_HOME/jk/native/apache-2.0

g) Copy the mod_jk.so file created in Step F to /path/to/apache/modules/.

NOTE: the ./configure method assumes you have a sane build environment: libtool, GNU make, autoconf, m4

a) cd to CONNECTOR_HOME/jk/native.

b) check README and README.configure.

c) run buildconf.sh: ./buildconf.sh. This will create a file called "configure" in CONNECTOR_HOME/jk/native.

d) run configure: ./configure --with-apxs=/usr/local/apache2/bin/apxs --with-java-home=${JAVA_HOME}

e) run make: make

g) You should end up with a mod_jk.so file in CONNECTOR_HOME/jk/native/apache-2.0. Copy that mod_jk.so file to /path/to/apache/modules/.

3) Edit server.xml in CATALINA_HOME/conf.

- look for a line that says "Server" and has a port of 8005. Add the following directly below:

<Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" modJk="/usr/local/apache2/modules/mod_jk.so" />

- in the Host container add the following Listener directive (yes, it looks very similar to the one above):

<Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" append="true" forwardAll="false" modJk="/usr/local/apache2/modules/mod_jk.so" />

- change the name parameter in the Host directive to your apache ServerName (the default is localhost)

4) Edit httpd.conf in APACHE_HOME/conf.

- make sure your ServerName matches the name="" parameter in your tomcat Host element in server.xml
- add the following line at the very end:

Include /usr/local/tomcat/conf/auto/mod_jk.conf

Note: the mod_jk.conf file gets created by tomcat when tomcat starts. It gets created every time tomcat starts. So, if you have your server.xml configured, you can ignore httpd.conf (in most cases) except to add the Include directive for mod_jk.conf. You don't need to create or edit mod_jk.conf. Click here for a sample mod_jk.conf file generated automatically by tomcat on each startup.

5) Create a file in CATALINA_HOME/conf/jk called workers.properties. That file should look like this:

# BEGIN workers.properties
#
# Setup for apache system
#
# make this equal to CATALINA_HOME
workers.tomcat_home=/usr/local/jakarta-tomcat-4.0.4
#
# make this equal to JAVA_HOME
workers.java_home=/usr/java/j2sdk1.4.0_01
#
ps=/
worker.list=ajp12, ajp13

# Definition for Ajp13 worker
#
worker.ajp13.port=8009

# change this line to match apache ServerName and Host name in server.xml
worker.ajp13.host=localhost

worker.ajp13.type=ajp13
#
# END workers.properties

6) Startup tomcat.

7) Wait at least 10 seconds for tomcat to finish. Start apache.

8) Verify examples at http://localhost:8080/examples. On success, tomcat is working correctly.

9) Verify examples at http://localhost/examples. On success, apache is working correctly, and JSP and servlet requests are being passed to tomcat.

Back To Menu

Please send comments, suggestions, or changes to john AT johnturner DOT com. Be advised that I will be happy to help where I can, but I am not available for free one-on-one tech support to the whole world. :)

Copyright © 2002 John Turner. All rights reserved.