• 07
  • Jul, 05

Apache (HTTPD) and Tomcat connector with mod_jk

I’ve spent the last few days trying to figure out how to get the mod_jk connector working so that I can use tomcat and httpd together. The problem, like most linux operations, is that it’s very poorly documented. Not only that, but the decent documentation you find is either outdated or is very specific to the writers desired configuration, and things don’t always work right when you try to revert those instructions back to a “default” configuration for your own use. I hope to document my finding before I forget them, and in a manner that is easy for anyone to understand.

First, you need to install 4 things: Apache, Tomcat, JDK, and Apache2-devel. As of this writing, the latest versions are Apache 2.0, Tomcat 5.5, J2EE SDK 1.4, and Apache2-devel is the development tool for Apache2 that will be needed to create the mod_jk connector. I was able to install Apache2 and Apache2-devel as RPMs in Mandriva (formerly Mandrake) LE 2005 (10.2). For instructions on how to install Tomcat and JDK, check out Integrating Tomcat and Apache on Red Hat Linux <–this site is an excellent resource, but after following it’s instructions to a “T”, I was never able to get things working. I’ll refer to this site often, and let you know what WAS useful from it. Hopefully if you are to the point where connecting Tomcat and Apache is important to you, you have already figured out enough about Linux that installing these 4 things isn’t too big of a problem for you.

The next thing you should do is build the mod_jk connector. The Apache website will try to convince you that you should just download a binary rather than build it from source, but I was much more successful building my own than using the binaries from Apache. Once again the Apache website’s documentation is a freaking mess! I’ll refer to it occasionally and let you know what WAS useful. To build the mod_jk connector, refer to section 4.3 on the Integrating Tomcat and Apache on Red Hat Linux page. These instructions are clear and precise so I won’t bother re-writing them here.* One thing I will mention that those instructions were unclear about, is that you need to be inside the CONN_SRC_HOME/jk/native/ directory in order to run ./buildconf.sh and ./configure, otherwise you will get errors. I also had to copy moc_jk.so to /usr/lib/apache2/ instead of where he put it.

Next you need to create a workers.properties file and place it in the /etc/httpd/conf directory. Using the Minimum workers.properties from Apache’s documentation worked for me. Just copy and paste everything in the blue box into your workers.properties file.

Next follow the instructions on the Apache website under the subsection titled Using Tomcat auto-configure. These instructions are written backwards, so remember that you need to do the second part before you even know how to do the first part because depending on your flavor of Linux, the mod_jk.conf file will end up in different places and with different names. I also added workersConfig=”/etc/httpd/conf/workers.properties” to my server.xml file to get this to work, like this:

<Listener className=”org.apache.jk.config.ApacheConfig” modJk=”/usr/lib/apache2/mod_jk.so” workersConfig=”/etc/httpd/conf/workers.properties” />

In tomcat’s default server.xml file, I put this <Listener> tag just between </Host> and </Engine> at the bottom of the document.

Next, copy the Simple configuration example into the bottom of your httpd.conf file. If you are indeed using Apache 2.0, be sure to remove the line “Add Module mod_jk.c”. If you are using Tomcat 5.x, change the /examples/ directories to /servlet-examples/ and /jsp-examples/ respectively, since they are now broken out like that instead of being lumped together.

Now restart both Apache and Tomcat and you should be good to go. The way I tested was by going to localhost:8080 and in the left hand side of the default tomcat screen there is a section titled “Examples”. Click on either JSP Examples or Servlet Examples and then choose an example listed there (preferably the “Hello World” examples, of course!). Now just replace localhost:8080 in your address bar with localhost (port 80) and you should see the exact same examples but without the static content (such as images). The configuration above assumes that your application’s static html files will be served from your Apache directory and dynamic files (servlets and jsp’s) will be served from your tomcat directory.

VUOLA!

*If for some reason a site goes down and a link is broken, please let me know! Even if you are reading this 3 years from now! A lot of my frustrations from getting this to work were broken links and I’d hate for this documentation to become one of those.

Share and Enjoy:
  • Digg
  • Reddit
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Technorati
  • TwitThis
  • E-mail this story to a friend!

12 Responses

  1. Sorry :(

  2. Hi!
    Thanks for the manual.
    But the links doesn`t work (e.g Integrating Tomcat and Apache on Red Hat Linux). Can you fix it?

    Thanks.

    David

  3. I contacted the site’s owner and it should be back up again. Thanks for the heads up.

  4. Yes now it works fine!!!
    Thank you very much ;-)

  5. I have started tomcat, but I cannot find the mod_jk.conf-auto file. Why would this be? Thanks for any help!

  6. Ok, I figured that part out. I had apache2 running–oops!

    Now everything should be setup correctly, but I am getting an error when I start apache2: “Invalid command ‘worker.list=worker1′, perhaps mis-spelled or defined by a module not included in the server configuration”.

    Any ideas?

    I copied the minimum workers.properties given in this tutorial.

  7. Please disregard–fixed it.

    Come to find out, I was getting the error because I had workers.properties stored in /etc/apache2/conf.d/
    I moved it to /etc/apache/ and it worked.

    Sorry for the list of questions, but hopefully this will help anyone else that comes across the same issue.

    FYI, I have used the jakarta-tomcat-connectors-1.2.15.src to build on Debian Sarge and it worked fine.

    Furthermore, if you do not have apxs, you can install the latest version for Apache2 from debian.org. It is packaged within the apache2-threaded-dev package.

    Hope this helps any Debian users.

    Good luck!

  8. Hi,
    I’m trying to install Tomcat with Apache as you did in this article but have failed utterly to install the apxs module. I found the apache2-devel 2.0.53 rpm but on installation I was faced with a list of failed dependencies : apr-devel, apr-util-devel, autoconf2.5, automake1.7, perl-base, multiarch-utils. As I installed originally from a RedHat Enterprise 4.2 CD I did not tailor Apache at all and can only assume I’m missing some modules. I’ve tried searching for the missing rpms but on application they in turn seem to be missing dependencies.
    I’m quite new to Apache and Tomcat so any pointers would be appreciated.
    Thanks in advance.

  9. My original intent with connecting Apache and Tomcat was so that I could use JSP driven apps (such as SiteMesh and Laszlo) but also use PHP. I have since learned that you don’t even need a connector, but that Tomcat will also run PHP.

    Perhaps before attempting to connect them you could read Why should I integrate Apache with Tomcat? (or not) and then Using PHP With Tomcat. It’s possible you can achieve what you are looking for a lot quicker and easier!

  10. I have been trying to set something like this up for a week now.. There is no place on the internet that can describe this in a decent way (yes, I have looked at most the tutorials out there, pretty deprecrated all of them)

    I need to install this on a RHEL 4 server. If anyone has done this and could send/show me there config files I would be really happy. why the hell don´t tutorial writers do a little summary with config files and affected directories and so on? (no hard feeling towards anyone, I´m just really tired and frustrating not being able to get this working, I miss gentoo it would have been 3-4 commands and a auto working server)

    Anyway if anyone can help me I will be in your debt.

  11. I´m trying to set the CONN_SRC_HOME = /usr/src/jakarta-tomcat-connectors-1.2.8-src, but I have no idea what to wright in the promp, yes sure Iḿ new in Linux.
    Would you please help… will be very appreciate

  12. The manual was helpful and i could succesfully install mod_jk.
    Also, i am almost successful in intetrating tomcat5.5, apache 2.0 and mod_jk. But there is a small problem.
    for e.g. my servername is http://www.domain1.com
    then when i give http://www.domain1.com i want to invoke an application called sample/index.jsp which is located in tomcat webapps folder. what should i change in my httpd.conf to achieve this? please let me know
    Thanks
    Sridevi

Leave a Reply

Car Humor | U2 News