Tag: linux

Deploy multiple virtual hosts on Tomcat 6

Dedicated to those of you who have spent TOO much time on this way under-documented topic:

First let’s start with a tomcat file structure.

TOMCAT FILE STRUCTURE

1. webapps – folder where applications should be placed to run (unless unpackWARs is set to false)
2. work/Catalina/host_name – place where temporary files are created when Tomcat is running, eg: servlet classes
When “unpackWARs” is set to false (in server.xml) entire site structure is created
* we should not care about this directory much because it is generated dynamically each time

DEPLOYING HOSTS without actual file structure
Add line as follows, and that’s it:

<Host name=”xxx” appBase=”webapps”
unpackWARs=”false” autoDeploy=”true”
xmlValidation=”false” xmlNamespaceAware=”false” >
<Context path=”” docBase=”/wherever/xxx.war” debug=”0″ reloadable=”true”/>
</Host>

* note: this way application FILE STRUCTURE is not created, probably because “webapps” folder cannot be used. Not sure about this one though, whatever the reason is what is important that no error messages are generated and application gets created in work/Catalina directory and, apparently, works happily from there.

– The problem with this approach is that if we cannot deploy web application that will read files on the server side.
– Application will fail to find files on the server, because files do not exists. Actually they exist in work/Catalina directory, however it is not the path application looks for while running. Application MUST be physically located in WEBAPPS directory for files to be found.

DEPLOYING HOSTS with actual file structure (THE RIGHT WAY!)
Add line as follows:

<Host name=”xxx” appBase=”webapps/xxx”
unpackWARs=”false” autoDeploy=”true”
xmlValidation=”false” xmlNamespaceAware=”false” >
<Context path=”” docBase=”/wherever/xxx.war” debug=”0″ reloadable=”true”/>
</Host>

Create directory in webapps folder called xxx. Copy-paste “manager” and “host-manager” directories from “webapps” directory to this directory. This step is very important, otherwise you will get this extremely annoying error in log files:

SEVERE: Error starting static Resources

…xxx/host-manager does not exist or is not a readable directory

Some online documentation will claim that you will need to mess with /conf/Catalina/xxx folder. Maybe with older Tomcat versions you will need to do that. I tested with version 6.0.32, all files in that folder are automatically generated.

Hope it makes someone’s life easier!