This HowTo will discuss how to install Apache and Tomcat on CentOS4. And if the title isn’t self explanatory enough we will be using mod_jk to link Apache and Tomcat.

  1. Let’s install Apache to start…

shell> yum install httpd

  1. Now let’s download the Java JDK from http://java.sun.com/javase/downloads/index.jsp (It is labeld as JDK 6u1)

  2. After clicking on Download we are going to look for “Linux Platform - Java™ SE Development Kit 6 Update 1”

  3. Download the “Linux RPM in self-extracting file” the filename should be jdk-6u1-linux-i586-rpm.bin

shell> mkdir -p /usr/java/
shell> mv jdk-6u1-linux-i586-rpm.bin /usr/java
shell> chmod a+x /usr/java/jdk-6u1-linux-i586-rpm.bin
shell> /usr/java/jdk-6u1-linux-i586-rpm.bin
shell> ln -s /usr/java/jdk1.6.0_01 /usr/java/jdk

  1. Next let’s download the following packages from http://archive.apache.org/dist/tomcat/tomcat-5/archive/v5.5.9/bin/ (Tomcat 5.5.9 used for this set of instructions)

  2. jakarta-tomcat-5.5.9-admin.tar.gz

  3. jakarta-tomcat-5.5.9.tar.gz

shell> tar xzvf jakarta-tomcat-5.5.9-admin.tar.gz
shell> tar xzvf jakarta-tomcat-5.5.9.tar.gz
shell> mv jakarta-tomcat-5.5.9 /usr/java/tomcat

  1. We can now setup an init script for Tomcat

  2. Download catalina to /etc/init.d

shell> chmod a+x catalina
shell> chkconfig -add catalina
shell> chkconfig catalina on

  1. Now we need to install the Tomcat Apache connector

  2. Download mod_jk from http://mirrors.dotsrc.org/jpackage/1.6/redhat-el-4.0/free/RPMS/mod_jk-ap20-1.2.15-1jpp.i386.rpm

shell> rpm -Uvh mod_jk-ap20-1.2.15-1jpp.i386.rpm

  1. Edit the workers.properties file in /usr/java/tomcat/conf

workers.tomcat_home=/usr/java/tomcat
workers.java_home=/usr/java/jdk
workers.list=ajp13
worker.ajp13.host=[fully qualified domain name]
worker.ajp13.cachesize=20
worker.loadbalancer.balanced_workers=ajp13

  1. Edit the server.xml file in /usr/java/tomcat/conf

  2. Immediately below the entry add:

  • Find the entry and change localhost to your fully qualified domain name or IP address.
  • This is also how you would define Tomcat virtual hosts. I won’t go into detail about virtual hosting with Tomcat. If you are interested in virtual hosting with Tomcat I suggest checking out some search results on Google.

  • Immidiately following that line add:

  1. Let’s now start up Tomcat. From the configuration changes made above Tomcat will generate an Apache conf file that will be used to load the Tomcat info.

shell> /etc/init.d/catalina start

  1. Now we need to do a few quick things for Apache to work with Tomcat.

shell> ln -s /usr/java/tomcat/conf/auto/mod_jk.conf /etc/httpd/conf.d/
shell> /etc/init.d/httpd start

  1. Let’s give it a test

  2. Open a web browser and navigate to http://[hostname]/jsp-examples

Side Notes: As you notice above, Tomcat is installed in /usr. /usr is usually not one of the larger partitions on a web server. In the past I have created a directory /var/www/tomcat, copied the contents of /usr/java/tomcat/webapps to /var/www/tomcat, delete webapps and then create a symlink from /var/www/tomcat to /usr/java/tomcat/webapps. I also recommend creating a directory /var/log/tomcat, deleting /usr/java/tomcat/logs and creating a symlink from /var/log/tomcat to /usr/java/tomcat/logs. Use your best judgment as to how you want to handle this.