This is version 26. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]

Using PHP with Tomcat

Thanks to the wonderful people at Resin, most PHP applications and websites can be used with Tomcat by installing Quercus.


Traditional PHP hosting introduces a number of security issues due to the way Apache runs all sites under the same www-data account. There are a number of work-arounds, but it's a continual balancing act between performance, flexibility and security.

PHP binaries are written in C, so new buffer overflows and similar issues are reported and fixed monthly by the PHP developers.

By using Quercus to run PHP at Metawerx, security is handled by your already secured metawerx java hosting account. PHP binaries are not used, because everything is recompiled into Java on the fly and run by the Java VM, as 100% java instead.


With Quercus, PHP is compiled into java classes when you change it (like JSP) and then gets all the performance benefits from Java and the HotSpot compiler.

For a normal PHP request, the PHP script is loaded, parsed and executed in separate processes. These are much slower than a Java VM running java classes in separate threads. PHP professionals increase the performance of their systems using caching methods and utilities to keep a PHP instance in memory rather than loading a new instance for each request. With Java, we don't have to worry about that however, because the PHP is compiled into java classes and run by the Java VM.

According to a performance report by Aaron Stewart using Drupal (a popular PHP application), Quercus ran on Resin at around 3.5-4x faster than a standard PHP install.

There is also a great article on JavaLobby about Quercus that is worth a read if you are planning on moving from a PHP-based host to Tomcat or Resin as your PHP engine of choice.

How to install Quercus

You can install Quercus into your application directly by checking the entries in it's web.xml file, and importing the libraries in it's lib folder, or as a separate application.

This guide will show how to install it as a separate application.

  • First, download Quercus from
  • You will now have a WAR file, this is the same as a ZIP file, so unzip it with WinZip, WinRAR etc...
  • We recommend uploading an unpacked WAR file, so that you have full access to the folder structure, and won't accidentally delete all your PHP applications by deleting the WAR
  • Create a folder called php in your /private-cgi-bin/tomcat folder or /webapps folder. You can call it anything you like, such as wp for wordpress. If you want to use PHP on the entire site, then use the ROOT folder.
  • Upload the contents of the quercus WAR file into the folder using FTP
  • Go to your Tomcat Manager and click Reload on the new php application

You should now be able to access http://yoursite/php and see the Quercus test index.php file

Most PHP software works fine with Quercus, so upload some PHP and try it out, or continue below to install some popular PHP software.

Installation Guides for popular PHP software

metawerx specific

referring pages