Monday, May 26, 2008

Put Apache Tomcat in its own directory, and your web applications in another

I recently took my first look at Apache Tomcat 6.0. I was inspired by Tomcat: The Definitive Guide, 2nd Edition, which covers Tomcat 6.0. It mentioned a way to separate the actual Tomcat distribution and binaries from the webapp data, but described it for environments that had it pre-installed as an RPM or DEB package.

As I'm writing this, the latest version is 6.0.16. Here's what I had to do to get my webapp code in a separate directory tree from the Tomcat binaries as downloaded straight from tomcat.apache.org.


  • Create a directory, say /home/joshuago/domain.com, where all the webapps for that domain are going to be.

  • Set CATALINA_BASE to the directory above. (Don't set CATALINA_HOME.)

  • Move conf, logs, temp, and webapps directories to /home/joshuago/domain.com/.

  • Run apache-tomcat-6.0.16/bin/startup.sh script as usual.

  • Start developing at /home/joshuago/domain.com/webapps/ROOT/.

Change the directories as convenient or as suits best practices for your particular environment.

If you have multiple sites (and multiple instances of Tomcat) you'll need to edit conf/server.xml to make them listen on separate ports.

blog comments powered by Disqus