I just got through set­ting up Tomcat5.5, Apache2, and mod_jk on a Red­Hat Enter­prise AS4.4 machine at work. In the past, I have done this by com­pil­ing each com­po­nent sep­a­rately and fin­gling with con­fig files until it all worked. But I wanted to stick with RedHat-approved RPM’s from the Red­Hat net­work to ease updates and patch man­age­ment, and to allow the orga­ni­za­tion to have sup­port options.

I had a lot of trou­ble find­ing any doc­u­men­ta­tion on how to do this any­where, so I thought I’d throw it out here for any­one in a sim­i­lar sit­u­a­tion in search of help.

The fol­low­ing are my notes, sprin­kled with a lit­tle help I got from a Red­Hat sup­port tech.

First, I had to enable the fol­low­ing chan­nel within the Red­Hat Net­work for this system:

–Red Hat Appli­ca­tion Server v. 2 (AS v. 4 for i386)

If you don’t have a RHEL license for updat­ing your sys­tem, you will need one.

Once those chan­nels were enabled, I installed the fol­low­ing pack­ages using up2date at the com­mand line:


# up2date tomcat5
# up2date tomcat5-webapps
# up2date tomcat5-admin-webapps
# up2date mod_jk-ap20

With the pack­ages installed, I set out to con­fig­ure a vir­tual host to pass requests to Tom­cat as needed by using the mod_jk con­nec­tor. The fol­low­ing steps explain how to do this for a web site called example.com using IP address 123.123.123.123. Sub­sti­tute your domain and IP accordingly.

Step 1. — Add mod_jk to Apache

In /etc/httpd/conf/httpd.conf add this:


LoadModule jk_module modules/mod_jk.so
<ifmodule mod_jk.c>
JkWorkersFile "/etc/httpd/conf/workers.properties"
JkLogFile "/etc/httpd/logs/mod_jk.log"
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
</ifmodule>

That loads the mod­ule into Apache, tells apache where the worker is that will han­dle jsp/servlets, and tells Apache where to record log entries for mod_jk.

Step 2. — cre­ate a new file called /etc/httpd/conf/workers.properties and add this to it:


[channel.socket:example.com:8009]
port=8009
host=example.com
[uri:example.com/*.jsp]
worker=ajp13:example.com:8009

Step 3. Cre­ate a vir­tual host in /etc/httpd/conf/httpd.conf like so:


<virtualhost 123.123.123.123:80>
ServerAdmin webmaster@example.com
ServerName www.example.com
DocumentRoot /var/www/html
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
# Deny direct access to WEB-INF
</virtualhost>

Step 4. Set up Tomcat5 by adding this to /etc/tomcat5/server.xml just before the very last </Engine> tag at the bot­tom of the doc­u­ment:


<host name="example" appBase="/var/www/html" unpackWARs="true" autoDeploy="true">
<context path="" docBase="" debug="0" reloadable="true"/>
<alias>www.example.com</alias>
<valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="web1_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
</host>

Still with me? We are almost done.

Step 6. Cre­ate a sam­ple jsp file called /var/www/html/test.jsp and add this to it:


Time: < %= new java.util.Date() %>

Step 7. Start up the ser­vices

# apachectl start
# service tomcat5 start

Step 8. Try it!

Browse to http://www.example.com/test.jsp

If all went well, you should see the system’s cur­rent date and time when you load the web page. Con­grats. Hope it works for you!

 

8 Responses to “Setting up Apache, Tomcat, and mod_jk on RHEL4

  1. Chris says:

    I may be the only one need­ing this exact infor­ma­tion! I have about half of the steps com­plete so far…I’ll knock out the rest Mon­day morning.…and stuff.

  2. Andreas says:

    Thanks for shar­ing this infor­ma­tion — I found it really help­ful. By the way, for RHEL ES 4.4 have a look at JPack­age 1.7b (http://www.jpackage.org/jppfaq.php) … The only thing you need in addi­tion to JPack­age is the RHEL ES 4.4 Extras Chan­nel and the eclipse-ecj pack­age from ftp://ftp.redhat.com/pub/redhat/linux/enterprise/4/en/RHDS3/i386/RPMS/eclipse-ecj-3.2.0-1jpp_2rh.i386.rpm

    By the way, the Spam Protection/Captcha (Please add x and y) is not very use­ful when an input error (after sub­mit­ting the form) throws away every­thing you typed … shouldn’t it dis­play an error and (!) the whole form again, includ­ing pre­vi­ous con­tent, not just a “please go back” mes­sage :-(

  3. Will says:

    I’ll take a look at that, Andreas.

    Thanks for remind­ing me to dis­able the captcha thing — I meant to do that earlier!

  4. will says:

    i’ve installed a new com­ment spam pre­ven­tion method. this com­ment is a test of that plugin.

  5. Dana says:

    Thanks for the info! Looks to me like the ‘Red Hat Appli­ca­tion Server v. 2′ chan­nel is the one that con­tains the tomcat5 package.

  6. costinel says:

    woa! i almost for­got how long it took to com­plete a tom­cat install in the past. i just setup recently a tomcat5.0 on a rhel5 box with apache and j1.4.x. i was pleased to dis­cover that the apache to tom­cat con­nec­tion part was just a sin­gle line in a file that already exists on the sys­tem — /etc/httpd/conf.d/proxy_ajp.conf (ofcourse, assum­ing you already have apache and jre and tom­cat running)

  7. ptashek says:

    Thanks for shar­ing. I’ve got Tom­cat up and run­ning in no time!

  8. DUDE! says:

    DUDE, the jsp code is bad! I pulled my hair out try­ing to fig­ure this out and it turns out the jsp code you listed has a white space that shouldn’t be there. =)

    Don’t get me wrong, I really appre­ci­ate the tuto­r­ial, it was spot on. Thanks for that. I’m finally glad I’ve got this god for­saken lan­guage work­ing on my rhel5 server. Thanks again!

Leave a Reply