Installing Tomcat 6.0.x Behind Apache 2.2.x

Apache TomcatInstalling Tomcat is relatively easy as most of the work has already been done for you. These instructions pertain to OS 10.5.6 and will probably work for OS 10.5.x and 10.4.x. Going before 10.4 will probably required you to install a newer JDK. I’m going to run through this as root again. Any time you see #, this is the command line prompt. Ok, let’s get started:

1) Check Apache
Find where httpd is with “find httpd”. You are either running the default in /usr/sbin/httpd or running your own version in /usr/local/apache2/ or similar. I’m going to assume you are running in /usr/local/apache2/ and that you followed my other tutorial on installing 64-bit Apache/PHP. Now check what modules you have installed with “/usr/local/apache2/bin/httpd -l” and you should see a list of mod_* entries.

We’re going to stick with the reverse proxy and not go the mod_jakarta route (trust me, this is easier and I’m not even sure mod_jakarta is even being worked on anymore). So what we need to see in this mod_* list is mod_rewrite and mod_proxy. If you followed my previous instructions, you’ll note that mod_proxy is NOT there. We will have to recompile Apache.

2) Compile Apache
Go into /usr/local/src/httpd-2.2.11/config.nice and add the line


right after the line


then from the command line:

# ./config.nice
# make
# make install

This will only compile/install the bits needed unless you ran “make clean” previously. The config.nice is handy as it is a record of your config options allowing you to easily make updates and recompile. So now try the “/usr/local/apache2/bin/httpd -l” command again and you should now see mod_proxy (plus some others).

3) Install Tomcat
Download the binary tarball into your /usr/local/src/ directory using “curl -O”. The current version is 6.0.18 – http://apache.inetbridge.net/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz

Once you have this, move it into the proper place:

# tar -xzvf apache-tomcat-6.0.18.tar.gz
# mv apache-tomcat-6.0.18 /usr/local/
# ln -s /usr/local/apache-tomcat-6.0.18/ /usr/local/tomcat

As I mentioned in a previous tutorial, I like to leave the version info intact and symlink from a generic name. This allows me to have different versions of tomcat installed in the same location and switch between them by changing the symlink. We now need to set the JAVA_HOME environment variable. This is most easily done in /etc/bashrc by adding the line:

export JAVA_HOME="/Library/Java/Home"

to the end of the file.

So now check to make sure Tomcat is working by executing the startup script /usr/local/tomcat/bin/startup.sh. The default port is 8080 so fire up a browser and check http://localhost:8080/. You should see a page stating you set up Tomcat successfully.

4) Secure Tomcat
Open the file /usr/local/tomcat/conf/tomcat-users.xml and uncomment everything between “tomcat-users”. You will need to add two more roles and at least change the default passwords. The “tomcat-users” stanza should look something like this:

<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="tomcat" password="{password}" roles="tomcat,admin,manager"/>
<user username="role1" password="{password}" roles="role1"/>
<user username="both" password="{password}" roles="tomcat,role1"/>

I believe this change will be picked up by Tomcat, but just in case, from the Tomcat bin directory run “shutdown.sh” then “startup.sh”. You should now be able to access the Admin links on the default page at localhost:8080.

5) Configure Apache
In your Apache config file – /usr/local/apache2/conf/httpd.conf – create a VirtualHost stanza for the hostname to pass on to Tomcat. Here is an example for the hostname tomcat.latko.org:

<VirtualHost tomcat.latko.org:80>
ServerName tomcat.latko.org
ServerAlias tomcat.latko.org
ServerAdmin chris [at] latko [dot] org
DocumentRoot /Library/WebServer/Documents/tomcat
ProxyPass        /
ProxyPassReverse /
ProxyPass        /manager
ProxyPassReverse /manager
RewriteEngine On
RewriteRule ^(.*)$$1 [P,L]

The app is the specific application you want running at this hostname. If there is no specific app, you can remove it from the arguments so

ProxyPass        /


ProxyPass        /

For further security, you should comment out both manager lines, making it inaccessible to anyone. Now going to http://tomcat.latko.org will take you directly to your Tomcat app or to the Tomcat root we saw at http://localhost:8080.

6) Tomcat Startup Configuration
You can increase the memory allocated to Tomcat by modifying the startup.sh script and adding the following line at the top:

JAVA_OPTS="-Xms128m -Xmx512m"

To have Tomcat automatically start on boot, create a file in /Library/LaunchDaemons/ called “org.apache.tomcat.plist” with the contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

If you have any questions about this process, I would be happy to answer them.

4 thoughts on “Installing Tomcat 6.0.x Behind Apache 2.2.x”

  1. Hi Chris,

    I appreciate your posting, I did make the proxy working by following your steps.

    the extra issue I face is, now the apache relays all requests (eg, static html pages) to tomcat, even I put these pages in doc root of apache, they can not be served by httpd.

    is there way to let httpd to serve docs in its docRoot and let tomcat to server servlets/jsp only ?


  2. @Jacques Use a rewrite rule to only proxy .jsp files. Also proxy pass is slower then using mod ajp. ajp and also passes across more information. Here is an example.

    RewriteEngine On
    RewriteRule ^/(.*.jsp)$ ajp://localhost:8009/$1

    This will only pass jsp requests to tomcat rather then every request ie static html

Leave a Reply

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