Skip to content

Setting up Apache, Tomcat, and mod_jk on RHEL4

I just got through setting up Tomcat5.5, Apache2, and mod_jk on a RedHat Enterprise AS4.4 machine at work. In the past, I have done this by compiling each component separately and fingling with config files until it all worked. But I wanted to stick with RedHat-approved RPM’s from the RedHat network to ease updates and patch management, and to allow the organization to have support options.

I had a lot of trouble finding any documentation on how to do this anywhere, so I thought I’d throw it out here for anyone in a similar situation in search of help.

The following are my notes, sprinkled with a little help I got from a RedHat support tech.

First, I had to enable the following channel within the RedHat Network for this system:

–Red Hat Application Server v. 2 (AS v. 4 for i386)

If you don’t have a RHEL license for updating your system, you will need one.

Once those channels were enabled, I installed the following packages using up2date at the command line:


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

With the packages installed, I set out to configure a virtual host to pass requests to Tomcat as needed by using the mod_jk connector. The following steps explain how to do this for a web site called example.com using IP address 123.123.123.123. Substitute 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 module into Apache, tells apache where the worker is that will handle jsp/servlets, and tells Apache where to record log entries for mod_jk.

Step 2. – create 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. Create a virtual 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 bottom of the document:


<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. Create a sample jsp file called /var/www/html/test.jsp and add this to it:


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

Step 7. Start up the services

# 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 current date and time when you load the web page. Congrats. Hope it works for you!

Published inInternetLinuxOSSoftwareTechWeb DevWork

8 Comments

  1. Chris Chris

    I may be the only one needing this exact information! I have about half of the steps complete so far…I’ll knock out the rest Monday morning….and stuff.

  2. Thanks for sharing this information – I found it really helpful. By the way, for RHEL ES 4.4 have a look at JPackage 1.7b (http://www.jpackage.org/jppfaq.php) … The only thing you need in addition to JPackage is the RHEL ES 4.4 Extras Channel and the eclipse-ecj package 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 useful when an input error (after submitting the form) throws away everything you typed … shouldn’t it display an error and (!) the whole form again, including previous content, not just a “please go back” message 🙁

  3. I’ll take a look at that, Andreas.

    Thanks for reminding me to disable the captcha thing – I meant to do that earlier!

  4. i’ve installed a new comment spam prevention method. this comment is a test of that plugin.

  5. Dana Dana

    Thanks for the info! Looks to me like the ‘Red Hat Application Server v. 2’ channel is the one that contains the tomcat5 package.

  6. costinel costinel

    woa! i almost forgot how long it took to complete a tomcat 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 discover that the apache to tomcat connection part was just a single line in a file that already exists on the system – /etc/httpd/conf.d/proxy_ajp.conf (ofcourse, assuming you already have apache and jre and tomcat running)

  7. DUDE, the jsp code is bad! I pulled my hair out trying to figure 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 appreciate the tutorial, it was spot on. Thanks for that. I’m finally glad I’ve got this god forsaken language working on my rhel5 server. Thanks again!

Leave a Reply to DUDE! Cancel reply

Your email address will not be published. Required fields are marked *