Apache 2.0.44 / Tomcat 4.1.18 / mod_jk for RH Linux 7.2

(last updated 02/02/2003)

First, you need a sane build environment. In the open source world, that means GNU tools. Make sure you have the following tools installed. If not, get them from your nearest RPM repository, or from the GNU site.

Install all of the packages listed above.

Apache + Tomcat is five major steps: build/install Apache, install JDK, build/install Tomcat, install a connector, configure. Since Tomcat is 100% Java, we'll use the binary install instead of having to deal with ant. My preference is to put things in /usr/local. Your preferences may differ, that's fine, it really doesn't matter as long as you remember where things are and make the appropriate changes in the instructions that follow. Paths, in this scenario, don't have much effect as long as you can guarantee that they are consistent. I'm also assuming here that you have some familiarity with basic system administration operations, like unpacking compressed archives with gunzip, etc.

Build/Install APACHE
=====================

  1. grab Apache source from a mirror. You want version 2.0.44. The filename is httpd-2.0.44.tar.gz. I typically put packages like this in /usr/local/packages.
  2. unpack it to /usr/local/src. You should have /usr/local/src/httpd-2.0.44 when finished.
  3. read INSTALL file for instructions
  4. build apache with: ./configure --prefix=/usr/local/apache2 --enable-ssl --enable-module=so

  5. when configure completes, run make.
  6. when make completes, run make install.
  7. You should now have an Apache instance in /usr/local/apache2. Verify config: /usr/local/apache2/bin/apachectl configtest
  8. If you get a "Syntax OK" message, startup Apache: /usr/local/apache2/bin/apachectl start
  9. Verify Apache is running: http://localhost. You should see the Apache welcome page.

Install JDK
=====================

  1. go to java.sun.com and download the J2SE: http://java.sun.com/j2se/1.4.1/download.html I prefer the SDK versions over the JRE versions.
  2. Set JAVA_HOME as an environment variable, pointing to the location of the J2SE you just installed. How you set this environment variable is up to you. I typically set it in /etc/profile so that all users have it set by default.

Build/Install TOMCAT
=====================

  1. grab the Tomcat binary package for 4.1.18. Jakarta now uses the Apache style of download mirrors, so go here and choose a mirror, then click on the Tomcat link to download the binary for Tomcat 4.1.18: Jakarta Download Mirror.
  2. unpack it to /usr/local. You should end up with /usr/local/jakarta-tomcat-4.1.18
  3. add a symbolic link: ln -s /usr/local/jakarta-tomcat-4.1.18 /usr/local/tomcat
  4. set CATALINA_HOME as an environment variable, pointing to /usr/local/tomcat. This lets you change the version of Tomcat easily without having to change startup scripts, environment variables, etc.
  5. startup Tomcat to test your installation: /usr/local/tomcat/bin/startup.sh. Verify the Tomcat examples are available at http://your.server.name:8080/examples. Typically, this will be http://localhost:8080/examples.

Install Connector
=======================

The two connectors (JK and JK2) are different; JK2 is a complete rewrite of the earlier JK/AJP13 protocol. We'll cover building JK, with JK2 to come later.

Download a JK binary for Linux here: http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk/release/v1.2.2/bin/linux/i386/. The version there was compiled against Apache 2.0.43 and should be compatible with 2.0.44. Put the Apache module called mod_jk-2.0.43.so into /usr/local/apache2/modules.

Final Configuration
=======================

NOTE: these steps will allow access to the Tomcat examples via Apache on port 80. Successful use of the examples on port 80 shows that mod_jk is working correctly, since Tomcat is configured to run on port 8080 by default for HTTP requests.

  1. Edit server.xml in CATALINA_HOME/conf.
  2. 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" />

  3. 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" />

  4. change the name parameter in the Host directive to your Apache ServerName (the default is localhost)
  5. Edit httpd.conf in APACHE_HOME/conf. Scroll down to where you see a bunch of lines that say "LoadModule". At the end of this list, add a line that says:

    LoadModule jk_module modules/mod_jk-2.0.43.so

    ...also...

    - make sure your ServerName matches the name="" parameter in your Tomcat Host container 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.

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

    # BEGIN workers.properties
    worker.list=ajp13
    worker.ajp13.port=8009
    worker.ajp13.host=localhost
    worker.ajp13.type=ajp13
    # END workers.properties

  7. Startup Tomcat: $CATALINA_HOME/bin/startup.sh
  8. Wait at least 10 seconds for Tomcat to finish. Start Apache: /usr/local/apache2/bin/apachectl start
  9. Verify examples at http://localhost:8080/examples. On success, Tomcat is working correctly.
  10. Verify examples at http://localhost/examples. On success, Apache is working correctly, and JSP and servlet requests are being passed to Tomcat.

For more info, consult the Tomcat documentation as well as the Tomcat-user mailing list. If you want to use this HOWTO for something other than "localhost", then all you have to do is use "www.your-domain.com" everywhere it says "localhost". My advice in that scenario would be to copy the existing, default Host container in Tomcat's server.xml, and change the "name" parameter to "www.your-domain.com", then restart Tomcat (to re-gen mod_jk.conf with the new hostname) and restart Apache. Making a copy of the localhost Host container in server.xml will leave the localhost container as a failsafe default, which might cut down on problems in the future.

NOTE: in Tomcat, virtual hosts are "Hosts". That is, as far as Tomcat is concerned, localhost is a virtual host. So, if you want to setup www.server-a.com and www.server-b.com, you just need more copies of the Host container included in the default server.xml that comes with Tomcat. Doing it in production is a little more complicated than that, but that's the essence of how to get Tomcat to work for more than localhost. Because this HOWTO describes using the Apache auto-config option of JK, getting Tomcat to work with your virtual hosts means Apache will work. This means that you can test your URL and your application contexts using ":8080" on your URL without affecting Apache. When you have it working, simply restart Apache so that it picks up the new mod_jk.conf file generated by Tomcat and you should be well on your way. If you need more information on the Host container, check the documentation: Host container reference.

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-2003 John Turner. All rights reserved.