Running Drupal on Quercus

Quercus was designed and built to run on Caucho's Resin application server, but it can also be downloaded separately as a Web Application Archive (WAR) file and run in any other Java application server that can handle the WAR. In this case, we will run it on the Apache Tomcat platform.

If you have not yet installed and configured Tomcat, please refer to my previous blog entries that describe performing a custom Tomcat installation and how to set up a basic configuration of that installation.

Download & Install Quercus

Download the Quercus WAR file from Caucho's site at We'll unpack it into a directory that corresponds to the virtual host name of the web server (www.quercusexample.lan in this case).

[geshifilter-code type="bash"] mkdir -p /opt/www.quercusexample.lan/ROOT cd /opt/www.quercusexample.lan/ROOT unzip /<path to downloaded file>/quercus-4.0.1.war [/geshifilter-code]

The JAR files that you need will then be located in the /opt/www.quercusexample.lan/ROOT/WEB-INF/lib/ directory. All three are necessary - inject-16.jar, javamail-141.jar and resin.jar.

Configure the Tomcat Web Application

To access the Drupal installation using the http://www.quercusexample.lan URL, we'll need to set up another <Host> element in Tomcat's server.xml file. Pull up the /opt/localhost/conf/server.xml file and add the following Host section after the existing Host:

[geshifilter-code type="xml"] <Host name="www.quercusexample.lan" appBase="/opt/www.quercusexample.lan" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> </Host> [/geshifilter-code]

Configure URL Rewriting

Using Drupal's clean URLs feature makes your site more user- and SEO-friendly, but Tomcat does not come with the necessary URL rewriting support to make it work. Fortunately the UrlRewriteFilter package from plus a bit of custom Java codesmithing can fill in the gaps and get it working. Lets download the and unpack it into your Quercus install directory.

[geshifilter-code type="bash"] cd ~ wget cd /opt/www.quercusexample.lan/ROOT unzip ~/ [/geshifilter-code]

The UrlRewriteFilter package provides the underlying framework for URL rewriting in Tomcat, but it still cannot determine if a request is attempting to access an actual physical file or directory, which is a necessary function for Drupal's clean URLs to work properly. To compensate for this, I created a couple of companion Java classes which provide the required functionality, and wrapped them into a single JAR file that you can include in your Tomcat installation. Here's how you can obtain and install this JAR:

[geshifilter-code type="bash"] cd ~ wget /opt/www.quercusexample.lan/ROOT/WEB-INF/lib tar --strip-components 1 -xzvf ~/drupalrewrite_0.1.tar.gz drupalrewrite/drupalrewrite.jar [/geshifilter-code]

Now we need to tell Quercus how to find and use the UrlRewriteFilter code and the drupalrewrite.jar file. Insert the following XML code into the /opt/www.quercusexample.lan/ROOT/WEB-INF/web.xml file, before any <servlet> definitions:

[geshifilter-code type="xml"] <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <init-param> <param-name>logLevel</param-name> <param-value>WARN</param-value> </init-param> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> [/geshifilter-code]

Also, make sure your Quercus Servlet definition in web.xml is configured to use a JDBC database that's already been configured in Tomcat. In a previous posting I described how to set up a MySQL data source named "jdbc/qdrupal", which we will use here: [geshifilter-code type="xml"] <init-param> <param-name>database</param-name> <param-value>jdbc/qdrupal</param-value> </init-param> [/geshifilter-code]

Next, insert the following XML code into /opt/www.quercusexample.lan/ROOT/WEB-INF/urlrewrite.xml:

[geshifilter-code type="xml"] <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC "-// UrlRewrite 3.2//EN" ""> <urlrewrite> <class-rule class="com.brianshowalter.drupalrewrite.DrupalRule" /> </urlrewrite> [/geshifilter-code]

When done, just restart Tomcat.

[geshifilter-code type="bash"] /etc/init.d/tomcat stop /etc/init.d/tomcat start [/geshifilter-code]

Install Drupal

The first step in installing Drupal (either stand-alone on Apache/PHP or on top of Quercus) is to create the database. Assuming that MySQL is running on the same machine as your Drupal installation and Tomcat has been configured to use it, below are the commands you need to run after logging into your MySQL client:

[geshifilter-code type="sql"] create database qdrupal; grant all on drupal.* to 'drupal'@'localhost' identified by 'drupal'; flush privileges; [/geshifilter-code]

Now we're ready to start the Drupal install. Download the latest Drupal tarball from, then extract it into the Quercus root directory:

[geshifilter-code type="bash"] cd ~ wget cd /opt/www.quercusexample.lan/ROOT tar --strip-components 1 -xzvf ~/drupal-6.14.tar.gz [/geshifilter-code]

When this is done, you should now be ready to visit http://www.quercusexample.lan:8080 and perform a normal Drupal install according to the instructions on the Drupal site at