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

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
    ServerAdmin [email protected]
    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!





Apache2 configuration


Tomca6 configuration


Restart Apache2 and Tomcat6

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

Share this page:

Suggested articles

5 Comment(s)

Add comment


By: David Allwhole

Wonderful tutorial :)

Many Thanks

By: runner


 my test.jsp is only accessible over port 8080. I can't find my failure. Any idea?

By: Anonymous

I have the same issue.


Thanks, this is THE best Tutorial I have come across for this. Helped me a bunch!

By: Marten

This works fine, except that in Tomcat 6 now the app is deployed twice! This can cause problems with scheduled job (Quartz jobs), being run twice.

 The Tomcat docs say this about it:

When using automatic deployment, the docBase defined by an XML Context file should be outside of the appBase directory. If this is not the case, difficulties may be experienced deploying the web application or the application may be deployed twice. The deployIgnore attribute can be used to avoid this situation.

Finally, note that if you are defining contexts explicitly in server.xml, you should probably turn off automatic application deployment or specify deployIgnore carefully. Otherwise, the web applications will each be deployed twice, and that may cause problems for the applications.


Thus, move the /var/www/ directory to ie. /var/www/ (that is, move it OUT OF the dir, which is the current 'appBase' in our server.xml)