This is the second part to the “How to Setup Tomcat to Run on Port 80”.
Part 2
  1. Configure httpd.conf
  2. Add init.d Script
  3. Restart HTTPD

Configure The Domain’s httpd.conf

You will need to add some entries to the domain.conf file in /etc/httpd/conf.d/ or in httpd.conf file. I prefer to utilize the conf files in /etc/httpd/conf.d/ and use httpd.conf inclusion because it is so easy to mess up the httpd.conf file.

vi /etc/httpd/conf.d/yourdomain.conf

Add the following code before the </VirtualHost> entry.

<Location /WEB-INF/ > # (1) AllowOverride None deny from all </Location> <Location /META-INF/ > # (2) AllowOverride None deny from all </Location> JkAutoAlias /home/userX/tomcat/webapps # (3) JkMount /* tomcat1 # (4) JkMount /*/* tomcat1 # (5) JkUnMount /php/* tomcat1 # (6)
1. Security location entry for WEB-INF
2. Security for META-INF too
3. Kind of an auto invoker for webapps within webapps dir.
4. Invokes tomcat1 worker for root directory in url /
5. Invokes the worker for any directory deeper than /.  I have seen problems with recursive directories in this case and found this to solve the problem.
6. Perhaps you want apache to run a particular directory and not Tomcat. Just add UnMount to tell Apache to render instead.

Setup init.d Script

You’ll want an init.d script to start up your container when you boot up or reboot your server.
Create a file called tomcat.sh and place it in /etc/init.d/ and put in the following contents:

<div id="_mcePaste">#!/bin/sh
# Tomcat Startup Script

start() {

echo -n "Starting up tomcat1"
su username -c /home/username/tomcat/bin/start.sh

}
stop() {

echo -n "Stopping tomcat1"
su username -c /home/username/tomcat/bin/shutdown.sh

}

# See how we are called.
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        *)
                echo $"Usage: tomcat {start|stop|restart}"
                exit
        esac
You will need to update the path to correctly point to your start and shutdown scripts. The su username -c is to insure that the system starts up your script as the unix user you have tomcat installed. Be sure to chmod the file to 755 so it can be executed when needed.

To complete this automation of the start up script, you will need to add a symlink in rc.3 in /etc/rc3.d/ as run level 3 is the default startup run level.
cd /etc/rc3.d/
ln -s ../init.d/tomcat.sh S99tomcatStartup
S is for startup and 99 is the process priority – you want tomcat to startup last.

Restart Apache

Finally best we restart httpd with service httpd restart to initialize in the updates we made to the domain.conf file.

Please leave comments. I am always interesting in learning better ways to do things.

« »