Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

How To Install Tomcat6 With SUN-Java And Apache2 Integration On Ubuntu 10.04 [Lucid Lynx] With Virtual Hosts

Apache Tomcat (or Jakarta Tomcat or simply Tomcat) is an open source servlet container developed by the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a “pure Java” HTTP web server environment for Java code to run.

Tomcat should not be confused with the Apache web server, which is a C implementation of an HTTP web server; these two web servers are not bundled together. Apache Tomcat includes tools for configuration and management, but can also be configured by editing XML configuration files.


1 Preliminary Note

This tutorial is based on Ubuntu 10.04 Server (Lucid Lynx), so you should set up a basic Ubuntu 10.04 server installation with Apache or a LAMP Server before you continue with this tutorial (e.g. as shown in this tutorial: Installing Apache2 With PHP5 And MySQL Support On Ubuntu 10.04 (LAMP)). The system should have a static IP address. I use as my IP address in this tutorial and as the hostname.

Make sure that you are logged in as root (type in

sudo su

to become root), because we must run all the steps from this tutorial as root user.


2 Installing Java Development Kit (JDK)

For easily adding a repository now and in the future you must install python-software-properties first:

apt-get install python-software-properties

Then run:

add-apt-repository “deb lucid partner”

Now update the Aptitude cache:

apt-get update

We will now install sun-java6-jdk which is available in the new repository, and openjdk-6-jdk:

apt-get install sun-java6-jdk openjdk-6-jdk

Accept the license agreement! with Ok and then Yes!

Let’s make sure Ubuntu and our future Tomcat check the sun-java6-jdk package first:

update-alternatives –config java

Choose the number that matches with /usr/lib/jvm/java-6-sun/jre/bin/java

Now check the Java version by typing:

java -version

It should look a lot like this (depends on java version in repo!)

root@ubuntu:~# java -version
java version “1.6.0_22”
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)


3 Installing Tomcat6

We can install Tomcat 6 via Aptitude like this:

apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-docs tomcat6-examples tomcat6-user


3.1 Declaring users and roles

Usernames, passwords and roles (groups) can be defined centrally in a Servlet container.

In Tomcat 6.0 this is done in the /etc/tomcat6/tomcat-users.xml file:

vi /etc/tomcat6/tomcat-users.xml

and add the following:

<role rolename="manager"/>
<role rolename="admin"/>
<user username="YOUR_USERNAME" password="YOUR_PASSWORD" roles="manager,admin"/>

Make sure you replace YOUR_USERNAME and YOUR_PASSWORD with your credentials, then save and exit the file.

3.2 Restart Tomcat6 and have a first test

/etc/init.d/tomcat6 restart

Then use your browser to visit and verify that you get the default Tomcat page.


You should also be able to visit with the credentials you have set above:


4 Integrate Tomcat6 on Apache2

First we install the Apache2 connector for the Tomcat Java servlet engine like this:

apt-get install libapache2-mod-jk


4.1 Configure the connector module

Now we can start configuring the connector module, first we create a new file which will hold our properties:

vi /etc/apache2/

Add the following to the file:


Save and exit the file.


4.2 Configure Apache2 to use the connector properties

Create a configuration file for Apache2 which will load when Apache starts:

vi /etc/apache2/conf.d/mod_jk.conf

Add the following to the file:

<IfModule mod_jk.c>
  JkWorkersFile /etc/apache2/
  JkShmFile /var/log/apache2/mod_jk.shm
  JkLogFile /var/log/apache2/mod_jk.log
  JkLogLevel info
  JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
  JkRequestLogFormat "%w %V %T"

Save and exit the file.

4.3 Setup a new virtual host in Apache2

Create the folders for our new virtual host:

mkdir /var/www/
mkdir /var/www/
mkdir /var/www/

Then create a new site in Apache2:

vi /etc/apache2/sites-available/

Then add:

<VirtualHost *:80>
    JkMount /* default
    DocumentRoot /var/www/
    ErrorLog /var/www/
    CustomLog /var/www/ combined
    <Directory /var/www/>
        Options -Indexes

Note: JkMount can be setup in different ways.

JkMount /* will use tomcat for all files
JkMount /*.jsp only for .jsp files
JkMount /folder/* for tomcat files in a specific directory

Enable the new virtual host we created, by running:



4.4 Setup a the new virtual host in Tomcat6

Open up the configuration file for Tomcat6:

vi /etc/tomcat6/server.xml

Find the following lines:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

And uncomment the connector port, like this:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Then scroll down and find:


AFTER the ending </Host> tag, and BEFORE the ending </Engine> tag, insert the following:

<!-- -->
<Host name="" appBase="/var/www/" unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="htdocs" debug="0" reloadable="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/www/"  prefix="tomcat_access_" suffix=".log" pattern="common" resolveHosts="false"/>

Make sure you replace with your details in all the places.

Now lets create a Catalina folder for our new domain:

mkdir /etc/tomcat6/Catalina/

And copy the original context files to new domain:

cp /etc/tomcat6/Catalina/localhost/* /etc/tomcat6/Catalina/

But remove the ROOT.xml file, because we don’t need that one on our new domain:

rm -f /etc/tomcat6/Catalina/


4.5 Create a test file and test our new setup

Create a new test.jsp file for our new virtual host:

vi /var/www/

and add:

        <title>Hello World</title>
        <h1>Hello World</h1>
        Today is: <%= new java.util.Date().toString() %>

Save and exit the file.

Finally restart the services, so that the new configuration will load:

/etc/init.d/apache2 stop
/etc/init.d/tomcat6 restart
/etc/init.d/apache2 start

Then use your browser to visit and verify that you get the test page we just created.


You should also be able to visit which is now also available on our virtual host (/docs, /manager/html and /host-manager/html should also work):


Your done!



  • Apache Tomcat: Official Site;
  • Apache Tomcat: Wiki;
  • Apache Tomcat Connector: mod-jk;
  • Ubuntu: Adding Launchpad PPA Repositories; Launchpad PPA Repositories
  • Ubuntu: Java;
  • Ubuntu: Sun Java; Java moved to the Partner repository
  • Ubuntu: Apache Tomcat;



Apache2 configuration


Tomca6 configuration


Restart Apache2 and Tomcat6

/etc/init.d/apache2 stop
/etc/init.d/tomcat6 restart
/etc/init.d/apache2 start