Setting up Apache2, Axis & Tomcat 5

I'm running a stock install of Fedora Core 3. So I have apache 2.0.52 running. I downloaded the latest stable binary version of Tomcat (5.5.4) and Axis (1.2RC2). I also obtained the binary release of mod_jk2. The download page indicates that JK2 is now officially unsupported. But I could'nt get mod_jk to work with Tomcat 5 so I stuck with this.

These instructions assume you have a Java environment all set up (paths, classpaths etc.) and are not afraid digging into your system config files. In addition I'll be working as root. (If all you want is to setup Tomcat and Axis for local testing you only need consider a modification of steps 1 & 2, such as installing in your home directory and ignoring the AJP details). So having got all the stuff we proceed as follows:

  1. Setting up Tomcat
    • Untar the Tomcat tarball into /usr/local/tomcat and set two shell variables , JAVA_HOME (to the toplevel directory of your Java installation) and CATALINA_HOME (to /usr/local/tomcat in this case). Its a good idea to place these in /etc/profile so that everybody can get them.
    • Make a Tomcat user and group by doing
      groupadd tomcat
      useradd -g tomcat -c "Tomcat User" -d /usr/local/tomcat tomcat
      passwd tomcat
      
      This saves us from having to run Tomcat as root.
    • If the web services you will present depend on common jar files or classes place these common files in $CATALINA_HOME/shared/lib and $CATALINA_HOME/shared/classes respectively. (Since I wanted to provide CDK webservices I copied the cdk-*.jar files as well as the vecmath*.jar file over to the Tomcat lib directory. For full CDK functionality I'd probably have to copy over all the files from $CDK_HOME/jar).
    • I basically used the default server.xml configuration file, though I changed instances of localhost to my FQDN. I also made sure that the <Connector> element existed for AJP1.3. It should look like:
         <Connector port="8009"
              className="org.apache.coyote.tomcat5.CoyoteConnector"
              enableLookups="false" 
              redirectPort="8443" 
              protocol="AJP/1.3"
              minProcessors="5" 
              maxProcessors="75"
              useURIValidationHack="false"
              protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"
         />
         
      (Taken from here) . During setting up it appears that a lot of the above can be skipped giving a pared down version
         <Connector port="8009"
              enableLookups="false" 
              redirectPort="8443" 
              protocol="AJP/1.3"
         />
      

  2. Set up the Axis web service
    • From the Axis tarball copy the directory called webapps/axis to $CATALINA_HOME/webapps
    • Copy your class files that will provide web services via Axis into $CATALINA_HOME/webapps/axis/WEB-INF/classes.
    • An important jar file that is required for Axis to run properly is activation.jar which represents the JavaBeans activation framework. You should get the zip file for the framework extract it to a directory. Then copy the file called activation.jar into $CATALINA_HOME/webapps/axis/WEB-INF/lib

  3. Setting up JK2
    • From the mod_jk2 tarball copy mod_jk2.so to /usr/lib/httpd/modules/ and workers2.properties to /etc/httpd/conf

  4. Modify Apache configuration
    • In /etc/httpd/conf/httpd.conf add the line
      LoadModule jk2_module modules/mod_jk2.so
      
    • In /etc/httpd/conf/workers2.properties define the Tomcat context that is to be handled. In this case we want the Axis services to be processed by Tomcat. So we have
      [uri:/axis/*]
      group=lb
      ...
      
      You can see my version here

  5. Test the setup
    • Start up Tomcat and then start up httpd
      sudo - tomcat -c $CATALINA_HOME/bin/startup.sh
      /etc/rc.d/init.d/httpd restart
      
      Point you browser to http://your.domain.name/axis and you should see the Axis welcome screen.
    • If you don't see the proper page or get an HTTP error check $CATALINA_HOME/logs/catalina.log and /var/log/httpd/error.log for clues as to whats wrong.

  6. Starting Tomcat at boot time
    • If you're running Fedora Core 3 (or above) then place this script into /etc/init.d (change the values of the variables if required) and then as root do
      cd /etc/rc5.d
      ln -s ../init.d/tomcat S84tomcat
      
Alternative Setup I recently upgraded to Apache 2.2 running on Fedora Core 5. As a result of this the mod_jk2 module is finally abandoned. In its place one can use mod_jk. However an alternative approach is to use the mod_proxy module of Apache which can handle AJP13. If you use this approach then you can ignore the workers.properties file described above (steps 3 and 4). Assuming that you have your Tomcat server running on http://localhost:8080/ the set up in your httpd.conf file is
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

...

ProxyRequests Off
ProxyPass /axis http://localhost:8080/axis
ProxyPassreverse /axis http://localhost:8080/
What this will do is pass on any requests such as http://your.domain.name/axis onto the web service named axis running under Tomcat. A restart of Apache should get things working. Also note that if you want to restrict access to the proxied resource you can add something like
<Proxy http://your.domain.name/axis/*>
Order deny,allow
Allow from all
AuthType Basic
AuthName "Tomcat Axis Webservices"
AuthUserFile /path/to/apachepasswords
Require user user1 user2
</Proxy>
This configuration will result in the situation that whenever a client tries to access the web service it is asked for a password. Alternatively one can specify valid IP's that are allowed to connect and so on. See here for more details.

Caveats & Acknowledgements

Most of this was pretty easy to set up with a lot of help from Google. I got a lot of pointers from a weblog and a useful HOWTO.

Now for caveats: I've never used Tomcat or Axis before this and most of the configurations are the default configurations, with very little extra added. My aim was to setup a webservice platform for me to test some specific code on and for other people to try it. So for example, my setup will not handle SSL connections. In addition, I really don't know whether this setup is secure or unsecure. If its the latter I'll soon find out.