Author: Jeff Peterson - jeff /at\ coded \dot/ com
Date: 10/08/2004
Version: 1.1
(c) 2004 All Rights Reserved
*******************************************************************************
** This document is provided for information purposes only. The author **
** does not provide any warranty or guarantee of fitness and expressly **
** disclaims all liability. Perform all actions AT YOUR OWN RISK! **
*******************************************************************************
Table of Contents
1. Introduction
2. Installing Java
a. Getting Java
b. Installing Sun Java
c. Preparing Dummy Packages (Woody)
d. Preparing Dummy Packages (Sarge / Sid)
e. Building and Installing Dummy Packages
3. Installing Tomcat4
4. Connecting Tomcat4 with Apache
a. Installing Mod-JK Connector
b. Configuring Apache
c. Configuring Tomcat4
d. Testing the Connector
5. A Note About Development Servers
6. Revision History
1. Introduction
This how-to describes the process involved for installing Java and Tomcat 4. Additionally, it details how to configure Apache to forward all Java-related (think JSP,etc) requests to Tomcat.
At last check, Debian has several antique versions of Java available. For licensing reasons, Sun's implementation is not available. This document will cover the steps necessary to seamlessly run Sun's implementation of Java on Debian.
At the time of writing, this document applies to Debian Woody and Sid. I have not tested it on Sarge but I would expect it to work.
This document assumes that you already have Apache installed and functioning.
2. Installing Java (source: http://wiki.osuosl.org/display/DEV/Java+on+Debian)
2.a. Getting Java
First step to installing Java is getting Java. For this we will use the Sun Java J2SE SDK. It is available through java.sun.com or more specifically, http://java.sun.com/j2se/downloads/index.html. I recommend to get the JDK for the most recent version but you may choose your favorite version >= 1.3.
2.b. Installing Sun Java
Once downloaded, make the JDK .bin file executable and then execute it. Accept the License. Watch as it extracts itself.
Move the extracted folder (jdk1.x.x) to /usr/local/lib/. This will probably require root privileges.
Create a symlink:
# ln -s /usr/local/lib/jdk1.x.x and /usr/local/lib/jdk.
I also like to have the following symlink:
# ln -s /usr/local/lib/jdk1.x.x /usr/local/java.
Set the privileges on /usr/local/lib/jdk1.x.x to your liking. I recommend
# chown -R root:src jdk1.x.x
Now we need to setup the environment so that java functions properly. Edit /etc/profile with your favorite text editor.
Add the following lines:
# Java stuff
export JAVA_HOME="/usr/local/lib/jdk"
export CLASSPATH=".:${JAVA_HOME}/jre/lib"
export JDK_HOME="{$JAVA_HOME}"
export PATH="{$JAVA_HOME}/bin:${PATH}"
This will add the Java binaries to the path and setup several other variables which are helpful.
2.c. Preparing Dummy Packages (Woody)
To get the Java packages recognized on Debain Woody is a bit more tricky. For Sarge and Sid, see below.
First of all we need to backport the java-common package from testing to stable.
This can be done simple enough by changing your /etc/apt/sources.list file.
Comment out all existing lines and add the following
deb http://mirrors.kernel.org/debian/ testing main non-free contrib
Update your sources
# apt-get update
# Install the java-common package
apt-get install java-common
Return your /etc/apt/sources.list to its original condition and re-update your sources
# apt-get update
Install some other packages that we are going to need
# apt-get install kaffe equivs
2.d. Preparing Dummy Packages (Sarge / Sid)
In order for Debian to recognize that Java is installed we need to jump through a couple hoops. This process will satisfy the dependencies that certain programs have on Java without using Debian's antique versions of Java.
In order to do this we are going to need to install a few debian packages (as root).
# apt-get update
# apt-get install install kaffe equivs java-common java2-common
2.e. Building and Installing Dummy Packages
Make yourself a temporary directory to build the dummy packages in.
# mkdir /usr/src/java
# cd /usr/src/java
Copy the dummy package control files to the temp folder and build them. For your convenience, the packages are available already compiled in the src/ directory of this document.
# cp /usr/share/doc/java-common/dummy-packages/*.control .
# equivs-build java-compiler-dummy.control
# equivs-build java-virtual-machine-dummy.control
# equivs-build java1-runtime-dummy.control
# equivs-build java2-runtime-dummy.control
# equivs-build java2-compiler-dummy.control
Now install the packages
# dpkg -i java*.deb
The next step is to tell Debian to use the new JDK. This is done with the update-alternatives command. There are a lot of commands so a script has been provided. Please see src/update-java-defaults.sh
The last thing to do is verify that Java is working. As root,
# java -version
This will create the system preference directories and verify that java is working.
Now Java is installed to Debian's satisfaction.
3. Installing Tomcat4
Under Debian the process for installing Tomcat4 is very strait-forward. I highly recommend using Tocat4 as opposed to other versions of Tomcat available.
To install Tomcat4 do the following:
# apt-get install tomcat4 tomcat4-webapps
Some additional packages will likely be automatically installed. Simple Huh?
Next lets configure Tomcat to use the Sun Java implementation. To do this, edit the file /etc/default/tomcat4. Set JAVA_HOME to /usr/local/lib/jdk. Done.
Restart Tomcat
# /etc/init.d/tomcat4 restart
We should now be able to test the tomcat installation. Open up a web browser and go to:
http://tomcat-server:8180
where tomcat-server is the machine running you just installed tomcat on. Make sure that the JSP and Servlet Examples work. Now we are ready to move on.
4. Connecting Tomcat with Apache
The next step is to provide seamless integration of tomcat into apache. It would be rather annoying for every customer to have to go to mydomain.com:8180. At the same time we don't want Tomcat to be serving non-java-based pages. This is because Apache is much faster and better at it.
The general approach is to use a connector between Apache and Tomcat which will allow Apache to dispatch JSP and Servlet requests to Tomcat for processing. At the same time, all non-Java-based pages will be handled by Apache.
4.a. Installing Mod-JK Connector
The first thing to do is install the Apache<->Tomcat connector
# apt-get install libapache-mod-jk
I recommend not having the httpd.conf configuration file auto-updated. It is prone to errors.
4.b. Configuring Apache
Edit /etc/apache/httpd.conf. Add the following line in the appropriate section.
LoadModule jk_module /usr/lib/apache/1.3/mod_jk.so
Add the virtual host(s) which will need JSP/Servlet support. To do this, add the following lines, customizing as necessary.