Submitted by brians on
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 http://quercus.caucho.com. We'll unpack it into a directory that corresponds to the virtual host name of the web server (www.quercusexample.lan in this case).
mkdir -p /opt/www.quercusexample.lan/ROOT cd /opt/www.quercusexample.lan/ROOT unzip /<path to downloaded file>/quercus-4.0.1.war
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:
<Host name="www.quercusexample.lan" appBase="/opt/www.quercusexample.lan" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> </Host>
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 http://tuckey.org/urlrewrite/ plus a bit of custom Java codesmithing can fill in the gaps and get it working. Lets download the urlrewritefilter-3.2.0.zip and unpack it into your Quercus install directory.
cd ~ wget http://urlrewritefilter.googlecode.com/files/urlrewritefilter-3.2.0.zip cd /opt/www.quercusexample.lan/ROOT unzip ~/urlrewritefilter-3.2.0.zip
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:
cd ~ wget http://www.brianshowalter.com/sites/default/files/drupalrewrite_0.1.tar.gz cd /opt/www.quercusexample.lan/ROOT/WEB-INF/lib tar --strip-components 1 -xzvf ~/drupalrewrite_0.1.tar.gz drupalrewrite/drupalrewrite.jar
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:
<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>
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:
<init-param> <param-name>database</param-name> <param-value>jdbc/qdrupal</param-value> </init-param>
Next, insert the following XML code into /opt/www.quercusexample.lan/ROOT/WEB-INF/urlrewrite.xml:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN" "http://tuckey.org/res/dtds/urlrewrite3.2.dtd"> <urlrewrite> <class-rule class="com.brianshowalter.drupalrewrite.DrupalRule" /> </urlrewrite>
When done, just restart Tomcat.
/etc/init.d/tomcat stop /etc/init.d/tomcat start
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:
CREATE DATABASE qdrupal; GRANT ALL ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY 'drupal'; FLUSH privileges;
Now we're ready to start the Drupal install. Download the latest Drupal tarball from http://www.drupal.org, then extract it into the Quercus root directory:
cd ~ wget http://ftp.drupal.org/files/projects/drupal-6.14.tar.gz cd /opt/www.quercusexample.lan/ROOT tar --strip-components 1 -xzvf ~/drupal-6.14.tar.gz
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 http://drupal.org/node/628292.