Installing Apache and Tomcat on CentOS4

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

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

  • After clicking on Download we are going to look for “Linux Platform – Java(TM) SE Development Kit 6 Update 1″
  • 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

3. 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)

  • jakarta-tomcat-5.5.9-admin.tar.gz
  • 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

4. We can now setup an init script for Tomcat

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

5. Now we need to install the Tomcat Apache connector

  • 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

6. 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

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

  • Immediately below the entry <Server port=”8005″ shutdown=”SHUTDOWN”> add:

<Listener className=”org.apache.jk.config.ApacheConfig”
modJk=”/usr/lib/httpd/modules/mod_jk.so”
workersConfig=”/usr/java/tomcat/conf/workers.properties”
jkLog=”/usr/java/tomcat/logs/mod_jk.log” jkDebug=”info” />

  • Find the entry <Host name=”localhost” appBase=”webapps” unpackWARs=”true” autoDeploy=”true” xmlValidation=”false” xmlNamespaceAware=”false”> 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.

<Host name=”[fully qualified domain name]” appBase=”webapps”
unpackWARs=”true” autoDeploy=”true”
xmlValidation=”false” xmlNamespaceAware=”false”>

  • Immidiately following that line add:

<Listener className=”org.apache.jk.config.ApacheConfig” append=”true” jkWorker=”ajp13″ />

8. 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

9. 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

10. Let’s give it a test

  • 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.

About Matt

IF YOU REALLY want to hear about it, the first thing you'll probably want to know is where I was born, and what my lousy childhood was like, and how my parents were occupied and all before they had me, and all that David Copperfield kind of crap, but I don't feel like going into it, if you want to know the truth.

In any case I am employed as a Senior Linux Systems Engineer at Rackspace in San Antonio, TX.

I spent the majority of my college years as an Astrophysics major specializing in black holes. When I got to my senior year and was studying 40 hours a week to stay on track I decided to bail and pursue an easier career.

I spend the majority of my time now contributing to WordPress, developing WordPress plugins, helping out in the WordPress IRC Channel, playing football (not American!), practicing Krav Maga, and last but not least, spending time with my Wife and Son.

This entry was posted in HowTo, Linux. Bookmark the permalink.

6 Responses to Installing Apache and Tomcat on CentOS4

  1. linuxamp says:

    Thanks for the excellent article! Worked great except for one thing (in my case). In step 9,

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

    should be:

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

  2. mdmartz says:

    Thanks for catching that! Step 9 has been updated.

  3. Cricdigs says:

    Does not work for me. Not sure how will apache know about this? Do we need to instruct Apache to divert jsp and servlets to mod-jk?

  4. Cricdigs says:

    Alrite, I get it now. The ln -s to mod_jk.conf is the key step in apache setup! sorry for the confusion..

    Only different setup I had was that my machine being 64-bit, i had to get different rpms…

    Thanks much!

  5. Thanks for this info. My programmer was looking for some info on this so I will pass this post on. Thanks for another great post.

  6. Krishnakumar says:

    it is not working

    i s trucked with following error

    “”"Starting httpd: httpd: Syntax error on line 210 of /etc/httpd/conf/httpd.conf: Syntax error on line 1 of /etc/httpd/conf.d/mod_jk.conf: API module structure `jk_module’ in file /etc/httpd/modules/mod_jk.so is garbled – perhaps this is not an Apache module DSO?

    [FAILED]“”"”

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre>