In this guide I'm using:
- Mac OS X 10.4.2
- The Mac OS X built-in Apache (version 1.3.33)
- Tomcat 5.5.9
- Jakarta Tomcat Connector 1.2.14 (JK-1.2.14)
[robg adds: Read on for the detailed setup instructions. I haven't tested this one, and there's a bit of assumed Terminal knowledge, but if you're installing Tomcat, you've probably got that already.]
Step 1: Download software
Go to the Tomcat 55 download page, and download the 5.5.9 tar.gz archive. You will probably need the 5.5.9 Compat tar.gz archive as well, from that same page. This is needed when running Tomcat with versions of Java older than 1.5, and Mac OS X 10.4.2 is using 1.4.2. Of course, you can install Java 1.5.x or later, and then you won't need Compat, but that's not covered in this guide.
Go to the this page, and navigate to find the latest version of JK for Apache 1.3.33. In my case, that's version 1.2.14 for Apache 1.3.33 [direct download link - 658KB].
Step 2: Installing and starting Tomcat
Locate the downloaded files. Double-click jakarta-tomcat-5.5.9.tar.gz and then the jakarta-tomcat-5.5.9-compat.tar.gz packages. When done, two folders will have been created:
- jakarta-tomcat-5.5.9
- jakarta-tomcat-5.5.9 2
- jakarta-tomcat-5.5.9 2/bin/jmx.jar to jakarta-tomcat-5.5.9/bin/jmx.jar
- jakarta-tomcat-5.5.9 2/common/endorsed/xercesImpl.jar to jakarta-tomcat-5.5.9/common/endorsed/xercesImpl.jar
- jakarta-tomcat-5.5.9 2/common/endorsed/xml-apis.jar to jakarta-tomcat-5.5.9/common/endorsed/xml-apis.jar
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
Press control-X, type Y, and then hit the Enter key. Tomcat is now installed, but not started.
Step 3: Make Tomcat start before login
To make Tomcat start as a deamon before you login to your computer, we need to create a startup item. Create a folder called Tomcat in /Library/StartupItems. Within that folder, create a text file called Tomcat with the following content:
#!/bin/sh
##
# Start Tomcat
##
. /etc/rc.common
ConsoleMessage "Starting the Java WebServices framework"
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
export CATALINA_HOME="/Library/Tomcat"
export TOMCAT_HOME="/Library/Tomcat"
export JWSDP_HOME="/Library/Tomcat"
sh ${TOMCAT_HOME}/bin/startup.sh
Make sure the file you just created is executable by typing the following in the terminal:
chmod 755 /Library/StartupItems/Tomcat/Tomcat
Then, create a file called StartupParameters.plist in /Library/StartupItems/Tomcat, with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>Description</key>
<string>Tomcat Servlet and JSP Server</string>
<key>Messages</key>
<dict>
<key>start</key>
<string>Starting Tomcat Server</string>
<key>stop</key>
<string>Stopping Tomcat Server</string>
</dict>
<key>OrderPreference</key>
<string>None</string>
<key>Provides</key>
<array>
<string>Tomcat</string>
</array>
<key>Requires</key>
<array>
<string>Resolver</string>
</array>
</dict>
</plist>
Step 4: Install Tomcat Connector JK and configure Apache to use JK and PHPIn the Terminal, cd into the download directory where the previously-downloaded Jakarta-Tomcat connectors file is located is located. Then type:
sudo mv jakarta-tomcat-connectors-jk-1.2.14-macosx-apache-1.3.33.so \
/usr/libexec/httpd/mod_jk.so
We now have to make some changes to the httpd.conf (Apache's configuration file). Open httpd.conf in pico by typing the following in the Terminal:
sudo pico /etc/httpd/httpd.conf
Of course you can use other text editors like TextWrangler, as long as you can edit with root privileges. The basics you need to know when using pico are that Control-W is used to locate a text string (search), and control-X exits the program and asks if you want to save (if you have made any changes). Using Control-W, locate the following two lines, and remove the # at the front of each line:
#LoadModule php4_module
#AddModule mod_php4.c
Next locate this line:
DocumentRoot "/Library/WebServer/Documents/"
and change it to read:
DocumentRoot "/Library/Tomcat/webapps/ROOT"
Now find this line:
Directory "/Library/Webserver/Documents"
and change it to:
Directory "/Library/Tomcat/webapps"
Next, find this line:
DirectoryIndex index.html
and change it to:
DirectoryIndex index.jsp index.html
Finally, go to the end of the file and paste this bit of code:
#
# Tomcat connector configuration
#
# Loads and adds the module
LoadModule jk_module libexec/httpd/mod_jk.so
AddModule mod_jk.c
#
# Tells Apache where the worker configuration file is
JkWorkersFile /Library/Tomcat/conf/workers.properties
# Logging options
JkLogFile /Library/Tomcat/logs/mod_jk.log
JkLogLevel error
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkRequestLogFormat "%w %V %T"
# All Applications in Tomcat automatically gets
# mapped and WEB-INF are automatically protected
JkAutoAlias /Library/Tomcat/webapps
# Deny direct access to WEB-INF in ROOT
#
<Directory /Library/Tomcat/webapps/ROOT/WEB-INF/>
AllowOverride None
Deny From All
</Directory>
# Files ending with .jsp or files with a directory named
# "servlet" in the url is sent to Tomcat (to worker ajp13)
JkMount /*.jsp ajp13
JkMount /*/servlet/* ajp13
Save your changes and close httpd.conf. Now everything is installed and configured.Step 5: Starting it up
In the Terminal, cd into Tomcat's bin directory and start tomcat:
$ cd /Library/Tomcat/bin
$ ./startup.sh
Tomcat should now be started and accessible at http://localhost:8080/. Go into System Preferences > Sharing and enable "Personal Web Sharing." Now try http://localhost/. Your webroot is /Library/Tomcat/webapps/ROOT/; that's where to put all your web files. Tomcat applications are accessible as a sub-directory (i.e. http://localhost/application_name/).
The only thing I haven't got working so far is that Apache doesn't respect index.jsp as an index file in Tomcat applications. If anyone finds a solution, please submit as a comment. Please, submit comments on this. Suggestions about the security and other configurations are more than welcome.

