Linux: Run tomcat with apache – mod_jk configuration

Disclaimer: I found an old note with these instructions on it. I’m sure that I’ve taken these from other blog(s) but unfortunately I cannot find the source to give complete credit to. Since this is a very useful how-to I decided to clean it up and publish it for everyone to read, but if author(s) stumble upon this page and provide a link to original document(s) I will be more than happy to give them full credit.

There are a few reasons why we’d want to configure Tomcat to run with Apache. For me the most important is security and the fact that I’d like to run my web servers on port 80. In order to run Tomcat on port 80 it has to run as root which is not safe and absolutely not recommended. I am going to show you how to configure your Apache to run and pass connections to Tomcat.

What I normally like to do in such situation is to compile Apache instead of installing from repositories, install and configure Java and Tomcat, and then complile mod_jk to provide Tomcat/Apache connector. Basically all steps will be manual. Perhaps all this can be done using repositories too, but this way I can keep things updated as they updates come out by the developers, not when they become available in repositories.

To simplify the solution and make it a universal tutorial, I am going to refer to each product by its name. Therefore we will be renaming all extracted folders to their generic names. For instance, latest versions of Apache, Tomcat, Java and mod_jk are 2.2.11, 6.0.18, 6u11 and 1.2.27 respectively (Jan 09), but we are going to refer to them as just Apache, Tomcat, Java and mod_jk. I have actually renamed them right after they were extracted before I placed them onto their permanent directories. I am going to use /usr/local as my installation directory but you can place them in /opt or any other directory you wish.

Most steps are performed under a non-root account. I will let you know when to use the root account.

Installing Apache:

Log on with your non-root account.
Download Apache tar package from and extract. This directory will be called “apache” from this point forward.
Change directory to apache ‘cd apache’.

Prepare the product to compile:

In apache directory:
./configure --prefix=/usr/local/apache
Change to root user: su
make install

Once it’s complete run apache:
/usr/local/apache/bin/apachectl start
test installation by browsing the target address. If it’s running then stop the process:
/usr/local/apache/bin/apachectl stop

Install Java (I’m using jdk):

Download Java self-extracting package from Whatever this file is, we call it java.bin.
Make it executable:
chmod +x java.bin
Once you’re done with the installation you will have a directory jre1xxxxx. We will refer to this directory as “java”.
Become root: su (to move directory to /usr/local)
Move the directory to its final resting place. Mine sits in /usr/local:
mv java /usr/local

Install Tomcat:

Download Tomcat from and extract the tar ball. We will call this directory “tomcat” from now on.
Become root: su (to move directory to /usr/local)

Move this directory to /usr/local:
mv tomcat /usr/local

Now it’s time to configure our paths. Edit your .bash_profile:

STOP: This is local to the user running Tomcat. Each user who’ll be running Tomcat should have a bash_profile in their own home directory.
nano ~/.bash_profile

and add the following lines:
export JRE_HOME=/usr/local/java
export JAVA_HOME=/usr/local/java
export CATALINA_HOME=/usr/local/tomcat

Save and exit, then execute the following command:
source ~/.bash_profile

Now test your Tomcat: as non-root user:

browse to http://localhost:8080. If it’s working then shut it down:

Installing connector (mod_jk):

Download mod_jk connector from and extract. We will call this new directory “connector”.
Go to connector/native.
To prepare:
./configure --with-apxs=/usr/local/apache/bin/apxs
Become root and:
make install
Check to see if is in /usr/local/apache/modules. If it’s there then you’ve so far been successful.

Create the connector:

Create a file called “connector.conf” in apache/conf directory:
nano /usr/local/apache/conf/connector.conf

and copy/paste the following lines in that file, save and exit:

Add the following lines to httpd.conf:
LoadModule jk_module modules/
JkWorkersFile conf/connector.conf
JkLogFile logs/mod_jk.log
JkLogLevel error
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /*.jsp myworker
JkMount /* myworker

Now, start both Apache and Tomcat. You should be able to view the Tomcat default page in http://localhost AND http://localhost:8080. This means that the connector is working. To increase security disable http access to Tomcat through port 8080.

Note: Apache will automatically start after reboot, but you will have to add Tomcat to your startup script manually. Here is a startup script you can copy to your /etc/init.d and make it executable to start/stop your server. I don’t remember where I got this script from, but just so you know, it’s not mine. Good thing about this script is that even if you run this as root, it will run your Tomcat server as user specified in line 6.

Note: become root to run Apache. If you use the following script for your Tomcat, you may also run it as root. It will switch to specified user once it’s executed. I don’t use the script, however, what I do is to add it to my root crontab and have run it as non-root user. This is the command I use:
su - <username> -c /usr/local/tomcat/bin/

Here is the script to run Tomcat (not mine, I found it in a mailing list):
# Tomcat Startup Script

TOMCAT_OWNER=<user who will run tomcat>; export TOMCAT_OWNER

start() {
echo -n "Starting Tomcat: "
sleep 2
stop() {
echo -n "Stopping Tomcat: "

# See how we were called.
case "$1" in
echo $"Usage: tomcat {start|stop|restart}"

CC0 1.0 To the extent possible under law, the creator has waived all copyright and related or neighboring rights to this work.

10 thoughts on “Linux: Run tomcat with apache – mod_jk configuration

  1. Vishwanath says:

    Thanks Ali, I was waiting for this configuration for more than 30 days. The configuration given by you works perfectly.

  2. i have installed java*.bin in my red hat linux 9 in /opt/SDK
    i have also installed tomcat6.0.20 in /root/tomcat6.0.20
    and i run the tomcat using ./sh
    but when i open http://localhost:8080 in my web browser.
    the default index.html page of java i.e /opt/SDK/domains/domain1/docroot/index.html
    is run every time……how do i run tomcat default page index.jsp/index.html page….
    plz help and reply

    • Check index.html in /tomcat/webapps/ROOT directory and make sure it’s not redirecting to another page. I wouldn’t install Tomcat in my /root directory to begin with, though.

  3. Hi Ali,

    I have followed the above instructions and configured apache tomcat.
    It was successful. I have deployed my application in
    It is working fine. Now I have a small problem when I click on some of the links in firefox, safari and other browsers. The html code is being displayed. Please have a look at the following link which works in IE and shows the code in firefox and other browsers.

    Please help ? Thanks in advance.

    • Unfortunately I am no html guru, but it seems to be a code problem. Page shows up in IE but with script errors, and plain text in Firefox. I don’t know if that qualifies it for MIME problem?

  4. Hi,

    This is the better tutorial that I have found on internet. it has all collective wisdom. I mean like apache, tomcat.mod_jk and each and every steps.

    done.. I’m success using this guide lines.. thanks for sharing with all others.great work..

  5. irfan says:


    I was trying to set the same but i donno for what reason i am not able to see the tomcat home screen when i start the host of apache http server.

    how to know where i have done mistake.Could i point to see that in any logs.

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.