Installing Tomcat and the Apache Portable Runtime on Debian Lenny

By Joel Barnum, Descriptor Systems. Last updated: 2010-7-28.


In this article, you will learn how to install the Apache Tomcat Web container and the Apache Portable Runtime on a Debian Lenny server.

Blatant, shameless plug: If you are not familiar with Tomcat and Java, I recommend that you get some training from Descriptor Systems. You can find more information at Thanks!

Installing the JDK

Tomcat 6 itself only requires a Java Runtime Environment (JRE), not a full Java Development Kit, but some of the other steps in this HOWTO require the JDK.

  1. Log into your Debian server, then open a root shell.
  2. Ensure that aptitude can find the JDK, by editing /etc/apt/sources.list and adding the text non-free to the end of the first line that starts with deb.
  3. In the root shell, install the JDK:
    aptitude update
    aptitude install sun-java6-jdk        

Installing Tomcat

While you can install Tomcat with apt-get or aptitude, I prefer to install it manually (just because).

  1. In the root shell, change to a temporary directory and download Tomcat. Note that you may need to adjust this URL to download from a different Apache mirror site:
  2. Untar the archive to your desired location for Tomcat. I prefer the opt directory:
    cd /opt
    tar zxvf /temp/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.tar.gz
  3. Create a new group and user for Tomcat (it's not good security to run it as root):
    groupadd tomcat  
    useradd -g tomcat -s /usr/sbin/nologin -m -d /home/tomcat tomcat
    chown -R tomcat.tomcat /opt/apache-tomcat-6.0.29        
  4. The above commands create the tomcat user without a shell, so if you ever want to switch to that user (e.g. in a startup script for Tomcat), you can use the following:
    su - -s /bin/sh tomcat          

  5. In your shell, change to the Tomcat directory and start it as a test:
    cd /opt/apache-tomcat-6.0.29
    bin/ start
  6. Look in the log and note the warning at the top that the Apache Portable Runtime is not installed (we do that in the next part):
    vim logs/catalina.out        
  7. Stop Tomcat:
    bin/ stop      
    rm logs/*

Installing the Apache Portable Runtime

According to the Tomcat docs, the Apache Portable Runtime (APR) provides performance benefits, especially if your Web applications use SSL or serve large static files. Unfortunately, the documentation for installing the APR is marginal, at best (thus the raison d'tre for this HOWTO).

Tomcat can use the APR only if the APR itself is installed and if Tomcat's so-called JNI native wrappers are present. You will set up and configure both of those here.

  1. In your shell, switch back to root.
  2. Install the APR itself, along with development packages that will be use by the build for the native wrappers:
    aptitude install libapr1 libaprutil1 libapr1-dev libssl-dev make        
  3. Point to the JDK so the build script can find it:
    export JAVA_HOME=/usr/lib/jvm/java-6-sun        
  4. Untar the native wrappers archive that's shipped with Tomcat:
    cd /opt/apache-tomcat-6.0.29/temp
    tar zxvf ../bin/tomcat-native.tar.gz
  5. Build and install the native wrappers:
    cd tomcat-native*/jni/native
    ./configure --with-apr=/usr/bin/apr-1-configure
    make install
  6. Ensure that the native library is in a location where Tomcat can find it:
     ln -s /usr/local/apr/lib/ /usr/lib/
  7. Switch back to the tomcat user and re-start Tomcat. Then look in the log: you should see a message like:
    INFO: Loaded APR based Apache Tomcat Native Library 1.1.120