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 http://ftp.de.debian.org/debian/ lenny main non-free

deb-src http://ftp.de.debian.org/debian/ 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

JAVA_HOME=”/usr/lib/jvm/java-6-sun/”

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.

wget http://apache.imsam.info/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz

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.

#!/bin/sh

# Tomcat Init-Script

case $1 in

start)

sh /opt/tomcat/bin/startup.sh

;;

stop)

sh /opt/tomcat/bin/shutdown.sh

;;

restart)

sh /opt/tomcat/bin/shutdown.sh

sh /opt/tomcat/bin/startup.sh

;;

esac

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′?>

<tomcat-users>

<role rolename=”manager”/>

<role rolename=”admin”/>

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

</tomcat-users>

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.

http://SERVERNAME:8080/manager/html

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 workers.properties at under given address.

vi /etc/apache2/workers.properties

workers.tomcat_home=/opt/tomcat

workers.java_home=/usr/lib/jvm/java-6-sun

ps=/

worker.list=default

worker.default.port=8009

worker.default.host=localhost

worker.default.type=ajp13

worker.default.lbfactor=1

JK configuration file

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

<ifmodule mod_jk.c>

JkWorkersFile /etc/apache2/workers.properties

JkLogFile /var/log/apache2/mod_jk.log

JkLogLevel error

</ifmodule>

/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

Apache

<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

</directory>

</virtualhost>

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

Tomcat

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”/>

</host>

/etc/init.d/tomcat restart

<alias>additionaldomain.com</alias>

Now Let’s create a Test page.

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

<html>

<head>

<title>Hello World</title>

</head>

<body>

<h1>Hello World</h1>

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

</body>

</html>

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

http://www.itoperationz.com/2009/07/multiple-instances-of-apache-tomcat-6-on-debain5-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;

http://www.itoperationz.com/2010/04/how-to-install-apache-tomcat-6-on-debian-5-lenny/

Leave a Comment

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