Final Configuration

This information is now maintained on my wiki http://www.mikepalmer.net/wiki/ApacheTomcatHowto.

NOTE: these steps will allow access to the Tomcat examples via Apache on port 80. Successful use of the examples on port 80 shows that mod_jk2 is working correctly, since Tomcat is configured to run on port 8080 by default for HTTP requests.

  1. First lets backup tomcats configuration file. It's always a good idea to back this up before we make any modifications to it:
    cd $CATALINA_HOME/conf
    cp -p server.xml server.xml.ORIG
    Now you've got a safe copy of server.xml as server.xml.ORIG. Worst case, you can copy it back and start over if something gets messed up.
  2. Now lets start tomcat and apache
    /etc/init.d/tomcat start
    /usr/local/apache/bin/apachectl start
  3. Test that apache is working by viewing http://IP_ADDRESS and check to see if mod_jk2 is passing requests to tomcat by viewing http://IP_ADDRESS/jsp-examples.

Multiple Hosts

By now, everything should be working in singular manner. (which is fine if that is all you need) But lets say you wanted to run seperate hosts for additional users. We need to do some more configuring. By now this segment assumes some premptive knowledge on Apache and it's configurations for multiple hosts. You can modify Apache's UserDir directive the same way using the Location directive.

  1. Edit httpd.conf to add a name based virtual host. It should look something like this;
    <VirtualHost *>
    ServerName host.example.com
    ServerAdmin user@host.example.com
    DocumentRoot /home/user/public_html
    ErrorLog logs/host.example.com-error_log
    CustomLog logs/host.example.com-access_log combined
    DirectoryIndex index.php index.html index.htm index.jsp
    <Directory /home/user/public_html/>
    AllowOverride All
    </Directory>
    <Location "/*.jsp">
    JkUriSet worker ajp13:localhost:8009
    </Location>
    </VirtualHost>
  2. Now lets create a name based virtual host in tomcat by editing /usr/local/tomcat/conf/server.xml and adding the information below after the last </Host> tag. (remember to stop tomcat first!):
    <Host name="host.example.com" appBase="/home/user/public_html">
    <Context path="" docBase="."/>
    </Host>
    Save your changes and exit the editor.
  3. Now we need to make another user for tomcats manager application. Edit /usr/local/tomcat/conf/tomcat-users.xml and add the user with the rights to the additional host
    <user username="username" password="pass" fullName="User Name " roles="manager"/>
  4. Now we need to copy the manager context into the host directory.
    cp -p /usr/local/tomcat/conf/Catalina/localhost/manager.xml /usr/local/tomcat/conf/Catalina/host.example.com/manager.xml
  5. Make sure the tomcat user has access to all the files
    chown -R tomcat:tomcat /usr/local/tomcat
  6. Now reload apache and start tomcat to test the virtual host
    /etc/init.d/tomcat start
    /usr/local/apache/bin/apachectl reload
  7. Verify examples at http://host.example.com/manager/html. On success, Tomcat will throw back the logon you just entered and you will then see the virtual host at the top of the manager application. This can attribute that the Tomcat Host is now functional. The porpose of the manager application is to deploy applications and allow development on the same system. Reloading the context every time it is loaded is only good for developing specific portions of an application, not a full application with intentions of full functionality under J2EE Specifications.


Back to Tomcat Shell Script Main