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
=====================
Install JDK
=====================
Build/Install TOMCAT
=====================
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.
<Listener className="org.apache.ajp.tomcat4.config.ApacheConfig"
modJk="/usr/local/apache2/modules/mod_jk.so" />
|
<Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" append="true" forwardAll="false"
modJk="/usr/local/apache2/modules/mod_jk.so" />
|
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.
# BEGIN workers.properties
|
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.
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. :)