Sebastian Mogilowski's Blog

Just another blog about administration, linux and other stuff

Install Tomcat 6 on Debian (Lenny) with virtual hosts and Apache2 integration

This article is a new version of my Apache Tomcat 5.5 article. In this version i descripe the installation of the open bluedragon in a seperate article. This article only describes how to install Apache Tomcat 6 on Debian Lenny, Apache2 integration and virtual hosts. Tocat 6 is not available over the regular sources on Debain Lenny (and Etch) it need to be installed by hand. (On Ubuntu you can get Tomcat 6 with an apt-Installation)

UPDATE: Please read the new article: Tomcat 7 on Debian

1. Install Java 6 runtime:

Choose one of the following Java JDK installations:

1.1 OpenJDK

aptitude install java6-runtime

1.2 Sun JDK (non-free)

vim /etc/apt/sources
deb http://ftp.de.debian.org/debian/ lenny main non-free
deb-src http://ftp.de.debian.org/debian/ lenny main non-free
aptitude update
aptitude install sun-java6-jdk

Note: Keep in mind that you need a different Apache connector configuration if you use the Sun JDK.

2. Download Tomcat

Download Tomcat 6 from Tomcat 6 Download page.

For example:

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

3. Install Tomcat

tar -xzvf apache-tomcat-6.0.18.tar.gz
mv apache-tomcat-6.0.18 /opt/tomcat

4. Create Init-Script

vim /etc/init.d/tomcat
#!/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

5. Activate the Tomcat manager

vim /opt/tomcat/conf/tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
    <role rolename="manager"/>
    <role rolename="admin"/>
    <user username="YOUR_USERNAME" password="YOUR_PASSWORD" roles="admin,manager"/>
</tomcat-users>

6. Start Tomcat

/etc/init.d/tomcat start

Now you can access the Tomcat manager with http://SERVER:8080/manager/html.

5. Install Apache2 connector

You can use the Tomcat as a standalone webserver, but the apache webserver has more features and you can use the apache modules. (mod_rewrite for example)

aptitude install apache2 libapache2-mod-jk
vim /etc/apache2/workers.properties
workers.tomcat_home=/opt/tomcat
workers.java_home=/usr/lib/jvm/java-6-openjdk
ps=/
worker.list=default
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

Note: Replace „/usr/lib/jvm/java-6-openjdk“ with „/usr/lib/jvm/java-6-sun“ if you using the non-free Sun Java runtime.

JK configuration file

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

6. Create a new VirtualHost

Creating a new VirtualHost: (In Apache AND Tomcat)

6.1 Create directories

mkdir /var/www/vhost1
mkdir /var/www/vhost1/htdocs
mkdir /var/www/vhost1/logs
vim /etc/apache2/sites-available/vhost1

6.2 Apache

<virtualhost www.testsrv.local>
    JkMount /*.jsp default
    ServerName www.testsrv.local
    ServerAdmin servermaster@testsrv.local
    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 can forward all files „JkMount /*“ or all files in a folder „JkMount /folder/*“ to the Tomcat, too.

a2ensite vhost1
/etc/init.d/apache2 reload

6.3 Tomcat

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

Note: You can add additional domains with:

<alias>additionaldomain.com</alias>

7. Create a Testpage

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

Now you can test your configuration with http://www.testsrv.local/test.jsp

, , , , , , , , , , ,

64 thoughts on “Install Tomcat 6 on Debian (Lenny) with virtual hosts and Apache2 integration

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

eMail-Benachrichtigung bei weiteren Kommentaren.
Auch möglich: Abo ohne Kommentar.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre, wie deine Kommentardaten verarbeitet werden.