Integrating Apache 2.0.x and Tomcat 4.x with mod_jk2 on Linux
This FlashGuideTM covers integrating Apache 2.0.x and Tomcat 4.x on Unix via mod_jk2. These instructions have been tested on SuSE 9.0, Red Hat 6.2 and Fedora Core 2. There are two ways to integrate Apache and Tomcat: mod_jk and mod_jk2. Mod_jk is the older but more stable version, which supports load balancing and non-standard web application locations. Mod_jk2 is newer, has bugs, and, as of 11/15/04, is no longer being actively developed.
These instructions are for the current version of Tomcat 4.1.31, but have worked the same for all previous versions of Tomcat.
1. Building Apache 2.0.x on Linux
Unless you can find a binary distribution of Apache with DSO support enabled, you will have to follow these instructions to build it yourself.
- Check your prerequisites:
- You will need GCC installed
- You will need /usr/ccs/bin and the gcc executables in your $PATH
- Download the latest Apache source from http://httpd.apache.org/download.cgi - currently, the latest is 2.0.52.
- Unpack the distribution into a development directory (I used /usr/local)
The distribution directory will be something like apache_2.0.52
- Cd into the distribution directory (e.g. /usr/local/apache_2.0.52)
- Configure the makefile:
./configure --with-layout=Apache --prefix=/usr/local/apache2 --enable-module=most --enable-mods-shared=most
If you have to run this configuration again, note that configure saves the latest configure command in config.status
- Build Apache:
make
- Install Apache:
make install
- Note the location of your Apache installation - we will refer to this as $APACHE2_HOME
2. Installing Tomcat 4 on Linux
- Download the latest Tomcat binary from the Tomcat 4 section of http://jakarta.apache.org/site/binindex.cgi. Currently, Tomcat 4.1.31 is the latest.
- Install Tomcat by unzipping/untaring the download file and placing in the desired directory (I used /usr/local)
cd /usr/local
tar zxf ./jakarta-tomcat-4.1.31.tar.gz
- Note the location of your Tomcat installation - we will refer to this as $CATALINA_HOME
- Optionally, save time on typing by creating a symbolic link like this:
ln -s jakarta-tomcat-4.1.31 tomcat4
3. Installing mod_jk2 on Linux
Follow these steps to install a binary copy of mod_jk2.
- Go to the JK 2 section of http://jakarta.apache.org/site/binindex.cgi and look in the folder for your OS. If you find one, download it. If you don't, skip to the next section.
- Rename the downloaded file to mod_jk2.so
- Copy mod_jk.so to $APACHE_HOME/libexec
4. Building mod_jk2 on Linux
Follow these steps if you can't find a mod_jk2 binary or just want to build your own.
- Check your prerequisites:
- Type 'which libtool' to see if libtool in your $PATH. If it is not, and it is really not on your system, you will need the latest libtools from GNU:
- Type 'which autoconf' to see if autoconf in your $PATH. If it is not, and it is really not on your system, you will need the latest autoconf from GNU:
On my system, I had to de-install older rpms for autoconf first.
- Download the latest JK 2.0 Tomcat Web Server Connectors from http://jakarta.apache.org/site/sourceindex.cgi. As of this writing, JK 2.0.4 is the latest.
- Unpack the distribution in the desired directory
Currently, the distribution directory is jakarta-tomcat-connectors-jk2-2.0.4-src
- Cd into the distribution directory
- Configure the makefile:
cd jk/native2
./configure --with-apxs2=/usr/local/apache2/bin/apxs --enable-EAPI
Replace the values of --with-apxs with the appropriate path to the apxs executable in your Apache installation directory.
- Now do the build:
make
- Finally, install
cd ../build/jk2/apache2/
$APACHE2_HOME/bin/apxs -n jk2 -i mod_jk2.so
This command will copy mod_jk2.so to $APACHE2_HOME/libexec, so make sure you have the appropriate permissions on the latter.
$APACHE2_HOME refers to the directory in which you installed the compiled Apache 2.x - in my case, it is /usr/local/apache2.
5. Configuring mod_jk2 for Apache 2.0.x
- Create workers2.properties in $APACHE_HOME/conf with the following contents:
[channel.socket:localhost:8009]
port=8009
host=127.0.0.1
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
[uri:/examples/*]
worker=ajp13:localhost:8009
- For Apache 1.3.x, edit $APACHE_HOME/conf/httpd.conf and add the following to the LoadModules section:
LoadModule jk2_module libexec/mod_jk2.so
- For Apache 2.0.x, edit $APACHE_HOME/conf/httpd.conf and add the following to the LoadModules section:
LoadModule jk2_module modules/mod_jk2.so
- Find the line in $APACHE_HOME/httpd.conf that starts with "Port" - make sure you have it pointing to a port that is not in use. Lately, Apache has been coming with the "Port" directive set to "8080", which is the same port that Tomcat will listen on. If you don't have any other web server running, you can set it to "80" instead.
- Test httpd.conf by typing the following:
cd $APACHE_HOME/bin
apachectl configtest
6. Testing
- Make sure no other server is running on the default Tomcat ports of 8005, 8009 and 8080. Make sure no other server is running on the Apache port, which is normally 8080 or 80.
- Start Tomcat first:
cd $CATALINA_HOME/bin
./catalina.sh start
Always start Tomcat first and then start Apache. If you have to bounce Tomcat, remember to take down Apache first and restart it after Tomcat restarts. mod_webapp is very sensitive that way. In fact, some users have reported that it is necessary to put in 10 second delay between starting Tomcat and Apache.
- Start Apache:
cd $APACHE2_HOME/bin
./apachectl start
- Point your browser to http://localhost and verify that you get the default Apache page
Substitute "localhost" for the actual machine name/ip if necessary.
- Point your browser to http://localhost:8080 and verify that you get the default Tomcat page
- Point your browser to http://localhost/examples/jsp/index.html and verify that you get the index page for the Tomcat examples. This will be served by Apache and will indicate that you have completed your integration of Apache and Tomcat successfully - congratulations!
Back to Table of Contents
|