How to Install and Configure Apache-Tomcat 6 on Debian 5 LENNY with apache2

This article is a „how to“ to install the tomcat with apache 2. I will try to explain each and every step so that if anything goes wrong one can revert it or can easily figure out the problem and correct it.

Installing Java 6 runtime:

Please try to install sun JDK because there is a big difference between configurations of sun JDK and open JDK. Installation of sun JDK is given as under;

Sun JDK (non-free)

deb lenny main non-free

deb-src lenny main non-free

Please copy and paste the above lines and add in /etc/apt/sources.list

vi /etc/apt/sources.list

Please update the aptitude by using the under given command.

aptitude update

aptitude install sun-java6-jdk

Go to /etc/profile and enter the path of the JDK if its not updated automatically.

Enter the path like under given;

export PATH


export JAVA_HOME

Download Tomcat

Now download tomcat 6 from the tomcat 6 download page.

For example:

Use wget to download the apache-tomcat to /tmp directory.


Installing Tomcat

tar -xzvf apache-tomcat-6.0.18.tar.gz

mv apache-tomcat-6.0.18 /opt/tomcat

Init script

vi /etc/init.d/tomcat

Change the permissions of the above created file to 0755 so that it can be executed at startup and also by giving the start/stop/restart command. Just copy and paste the under given text to the above given file.


# Tomcat Init-Script

case $1 in


sh /opt/tomcat/bin/



sh /opt/tomcat/bin/



sh /opt/tomcat/bin/

sh /opt/tomcat/bin/



exit 0

update-rc.d tomcat defaults

Enabling the Tomcat Manager

vi /opt/tomcat/conf/tomcat-users.xml

< ?xml version=’1.0′ encoding=’utf-8′?>


<role rolename=”manager”/>

<role rolename=”admin”/>

<user username=”USERNAME” password=”PASSWORD” roles=”admin,manager”/>


Start Tomcat

/etc/init.d/tomcat start

Now you can open Tomcat Manager with under given web address. Please replace the SERVERNAME with your server name or IP address.


Till here the tomcat server is installed and configured properly. There is a built in apache web server in the tomcat.

Installing the Apache2 Connectors

Tomcat has a built-in Web server, but the Apache2 web server is much more powerful as the Apache modules used. i.e. mod_rewrite

aptitude install apache2 libapache2-mod-jk

Now Create a file named at under given address.

vi /etc/apache2/








JK configuration file

vi /etc/apache2/conf.d/jk.conf

<ifmodule mod_jk.c>

JkWorkersFile /etc/apache2/

JkLogFile /var/log/apache2/mod_jk.log

JkLogLevel error


/etc/init.d/apache2 stop

/etc/init.d/tomcat restart

/etc/init.d/apache2 start

Creating a New Virtual Host

Now let’s create a new Virtual Host. This must be created in apache2 and Tomcat.

Creating Directories

mkdir /var/www/vhost1

mkdir /var/www/vhost1/htdocs

mkdir /var/www/vhost1/logs

vi /etc/apache2/sites-available/vhost1


<virtualhost www.testsrv.local>

JkMount /*.jsp default

ServerName www.testsrv.local

ServerAdmin [email protected]

DocumentRoot /var/www/vhost1/htdocs

ErrorLog /var/www/vhost1/logs/error.log

CustomLog /var/www/vhost1/logs/access.log common

<directory /var/www/vhost1/htdocs>

Options -Indexes



Note: You could also select all the files to the Tomcat forwared “JkMount / *” or all files within a directory “JkMount / folder / *”.

a2ensite vhost1

/etc/init.d/apache2 reload


vi /opt/tomcat/conf/server.xml

<!– www.testsrv.local –>

<host name=”www.testsrv.local” appBase=”/var/www/vhost1″

unpackWARs=”true” autoDeploy=”true”>

<context path=”" docBase=”htdocs” debug=”0″ reloadable=”true”/>

<valve className=”org.apache.catalina.valves.AccessLogValve”

directory=”/var/www/vhost1/logs”  prefix=”tomcat_access_” suffix=”.log”

pattern=”common” resolveHosts=”false”/>


/etc/init.d/tomcat restart


Now Let’s create a Test page.

vi /var/www/vhost1/htdocs/test.jsp



<title>Hello World</title>



<h1>Hello World</h1>

Today is: < %= new java.util.Date().toString() %>



See Also how to configure multiple Instances of Apache-Tomcat 6 on Debian 5 Lenny;

If you are looking for the information about the installation and configuration of apache tomcat 6 on debian lenny please visit the URL given as under;

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.