As the title is self descriptive, I'm trying to guide you how to run eg. drupal or wordpress on a java servlet container, for now, on Apache Tomcat 6; with help the Caucho's Quercus Engine. The wordpress is pretty much the same - but no urlrewrite needed at all.
As you may know, quercus is a reimplementation of php5 and its core libraries in java natively, which means, that no CGI trick has been adapted.
I did it on ubuntu, with the easiest way to have the necessary tools:
sudo apt-get install tomcat6 mysql
then
mysql -u root -p
create database drupal default character set utf8;
grant all privileges on drupal.* to 'drupal'@'localhost' identified by 'drupal';
which creates the database for drupal, then creates the drupal user with drupal password and grant all privileges.
now, it's time to configure tomcat, /etc/tomcat6/server.xml:
<!-- MySQL database resource -->
<Resource name="jdbc/drupal"
type="javax.sql.DataSource"
auth="container"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/drupal"
username="drupal"
password="drupal"
maxActive="10"
maxIdle="0"
maxWait="-1"
description="Drupal MySQL Data Source"/>
because quercus when deployed as a web app, it needs a JNDI lookup name for database connection, defined here.
created a pretty simple /var/lib/tomcat6/webapps/drupal
which is exploded from http://quercus.caucho.com/download/quercus-3.1.2.war:
META-INF/
META-INF/MANIFEST.MF
WEB-INF/WEB-INF/lib/
WEB-INF/lib/quercus.jar
WEB-INF/lib/resin-util.jar
WEB-INF/lib/script-10.jar
WEB-INF/web.xml
and modifying the web.xml to let quercus php engine to use our prepared JNDI database:
<!--
Tells Quercus to use the following JDBC database and to ignore the
arguments of mysql_connect().
-->
<!--
<init-param>
<param-name>database</param-name>
<param-value>jdbc/drupal</param-value>
</init-param>
-->
Now let's download the mysql's jdbc connector to /var/lib/tomcat6/webapps/drupal/WEB-INF/lib/ or, as I did,
sudo apt-get install libmysql-java
ln -s /usr/share/java/mysql.jar /var/lib/tomcat6/webapps/drupal/WEB-INF/lib/mysql.jar
only symbolic linking mysql connector to the webapp. I never put anything into tomcat's lib dir (/var/lib/tomcat6/lib/) which is not organic part of the tomcat, mysql, as in this example, part of the webapp, not the container!
the others pretty much the same as in the original quercus webapp .war file.
now, the an important, to download the urlrewrite module for servet container, to let drupal run properly, because installed drupal has this .htaccess file (used by Apache HTTPD), the essentials:
<ifmodule mod_rewrite.c="">
RewriteEngine on
[..]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</ifmodule>
download it and put it to WEB-INF/lib directory, ie. to /var/lib/tomcat6/webapps/drupal/WEB-INF/lib/urlrewrite-3.2.0.jar.
So we need to implement this under Tomcat. Since urlrewrite (ATM version 3.2) does not implements the REQUEST_FILENAME condition, we have two choices, first one to implement a custom class, as can be seen on http://www.brianshowalter.com/blog/running_drupal_on_quercus page, it's not so dynamic, since the install URI should be changed, so I decided to workaround, so I've put
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confReloadCheckInterval</param-name> <param-value>0</param-value> <param-name>confPath</param-name> <param-value>/WEB-INF/urlrewrite.xml</param-value>
<param-name>logLevel</param-name> <param-value>TRACE</param-value> </init-param></filter>
into the WEB-INF/web.xml to allow urlrewrite run and check it at every single hit, later the values recommended to change.
I placed the following config in WEB-INF/urlrewrite.xml (the whole file):
<?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" />
-->
<rule>
<from>\.(php|gif|css|jpg|png|ico|js|html|htm|txt)</from>
<to last="true">.$1</to>
</rule>
<rule>
<from>^/(.*)</from>
<to>/index.php?q=$1</to>
</rule>
</urlrewrite>
which have been taken from http://wiki.caucho.com/Quercus:_Drupal page, and does pretty much the same, not on Caucho's Resin, but on Apache's Tomcat with urlrewrite, the same thing is the Quercus PHP engine.
If the the URL ended with .php or .gif etc., no action is taken, that's why it is the "last", on other cases, it is rewritten to forward the request to index.php.
and for the sake of understanding, the whole WEB-INF/web.xml file:
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<description>Caucho Technology's PHP Implementation</description>
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>confReloadCheckInterval</param-name> <param-value>0</param-value> <param-name>confPath</param-name> <param-value>/WEB-INF/urlrewrite.xml</param-value>
<param-name>logLevel</param-name> <param-value>TRACE</param-value> </init-param></filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern></filter-mapping>
<servlet>
<servlet-name>Quercus Servlet</servlet-name>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
<init-param>
<param-name>license-directory</param-name> <param-value>WEB-INF/licenses</param-value> </init-param>
</servlet>
<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.php</welcome-file>
</welcome-file-list></web-app>
let's see what we got here:
find /var/lib/tomcat6/webapps/drupal/WEB-INF/ -ls
6826814 4 drwxr-xr-x 4 tomcat6 tomcat6 4096 Jul 30 17:40 /var/lib/tomcat6/webapps/drupal/WEB-INF/
6826870 4 drwxr-xr-x 2 tomcat6 tomcat6 4096 Jul 30 17:04 /var/lib/tomcat6/webapps/drupal/WEB-INF/lib
3064049 0 lrwxrwxrwx 1 tomcat6 tomcat6 25 Jul 21 11:38 /var/lib/tomcat6/webapps/drupal/WEB-INF/lib/mysql.jar -> /usr/share/java/mysql.jar
3065516 10296 -rw-r--r-- 1 tomcat6 tomcat6 10524501 Jul 1 16:47 /var/lib/tomcat6/webapps/drupal/WEB-INF/lib/resin.jar
6733981 368 -rw-r--r-- 1 tomcat6 tomcat6 371264 Jul 1 16:47 /var/lib/tomcat6/webapps/drupal/WEB-INF/lib/javamail-141.jar
6733982 96 -rw-r--r-- 1 tomcat6 tomcat6 91794 Jul 1 16:47 /var/lib/tomcat6/webapps/drupal/WEB-INF/lib/inject-16.jar
6733983 200 -rw-r--r-- 1 root root 198436 Dec 4 2008 /var/lib/tomcat6/webapps/drupal/WEB-INF/lib/urlrewrite-3.2.0.jar
6827312 4 -rw-r--r-- 1 tomcat6 tomcat6 2029 Jul 30 17:24 /var/lib/tomcat6/webapps/drupal/WEB-INF/web.xml
6826871 4 drwxr-xr-x 2 tomcat6 tomcat6 4096 Jul 1 16:47 /var/lib/tomcat6/webapps/drupal/WEB-INF/licenses
6827313 4 -rw-r--r-- 1 root root 454 Jul 30 17:40 /var/lib/tomcat6/webapps/drupal/WEB-INF/urlrewrite.xml
Make sure, that every file is under the permission of tomcat6:
sudo chown tomcat6:tomcat6 -R /var/lib/tomcat6/webapps/drupal/
and I'd recommend for now, NOT IN PRODUCTION to turn off the tomcat's java security in /etc/default/tomcat6 by:
# Use the Java security manager? (yes/no, default: yes)
# WARNING: Do not disable the security manager unless you understand
# the consequences!
TOMCAT6_SECURITY=no
and later to set up more granular settings in /etc/tomcat6/policy.d/*.policy
And at last but not least, the best news, that if we move /var/lib/tomcat6/webapps/drupal to another (eg. /var/lib/tomcat6/webapps/site or /var/lib/tomcat6/webapps/ROOT - which is the / on the site), it will work as well, and if you upgrade, you just need to update the urlrewrite configuration - no need to recompile your java classes!
Best luck for it!