GlassFish, PHP and WordPress

June 18th, 2008

With all the hype around JRuby, Jython, Scala, Groovy, etc., an oft-overlooked dynamic language with JVM support is PHP. Thanks to the hard work of the folks at Caucho Technology, the Quercus project offers a pure Java implementation of the PHP language, sporting support for a lot of the major PHP-based applications. In this entry, we’ll look at how to configure GlassFish to provide easy PHP support, and then look at installing WordPress, the popular blogging software (which runs this site) on GlassFish.

Installing the library

The first step, of course, is to download Quercus. As of this writing, the current version is 3.1.6 and can be downloaded here. The typical installation method is to wrap your PHP application inside the war, but that’s always felt a little odd to me. While that works, we’re going to setup GlassFish to process a PHP file from any application. To do that, let’s open up the Quercus war file, and look in WEB-INF/lib, where you will find 3 jar files. Now you have a choice. If you want to make PHP support available to all domains, place these three jars (quercus.jar, resin-util.jar, and script-10.jar) in the lib/ directory in your GlassFish installation root. If you only want to add support to one domain, copy the jars to the lib/ directory in your domain directory (e.g., $GF_HOME/domains/domain1/lib/).

Enabling PHP support

With the jars installed, we’re ready to modify the default web configuration. This is done by modifying config/default-web.xml in each domain directory you would like to affect. I have not seen a way to change this globally, so you have to do this to each domain. If someone out there knows how, though, I’m all ears. At any rate, in default-web.xml, add these servlet and servlet-mapping entries:

If you’d like, you can also add index.php to the welcome file list:

Installing WordPress

For our purposes, we’re going to make WordPress available at http://localhost:8080/wordpress, so we create the directory $GF_HOME/domains/domain1/docroot/wordpress. Next, we extract the WordPress archive here. Pointing our browser at http://localhost:8080/wordpress/, we see the typical WordPress installation screens. The first screen tells us that WordPress can’t find the configuration file, and offers us a link to create one. Click on that, then click on the “Let’s go!” link on the next page (feel free to read the page, of course ;).

On the form that is presented, fill out the requested information and click submit. We are now ready to begin the installation, so click the “Run the install,” answer two more questions, and click “Install WordPress.” After a few seconds, you should see the “Success!” page. Make a note of the password, and click “Log In.”

Voila!

You’re done! You now have WordPress installed and are ready to start blogging! Since we’ve done a directory installation, adding themes and plugins should be as straightforward as any run-of-the-mill PHP hosting setup. If anyone else tries this, I’d love to hear how the support for third party extensions is!

Technorati Tags: , ,

Popularity: 64% [?]

3 Comments »

  1. Björn says

    Hi!

    I use glassfish 2 and i tryed to install Quercus as you explain but i get a server error that looks like this:

    javax.servlet.ServletException: PWC1381: Error allocating a servlet instance

    root cause

    java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet

    root cause

    java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet

    Do you know something that can help me?

    Best Regards

    Björn

    August 21st, 2008 | #

  2. Daniel says

    Hey!

    Thanks mate, I just tested this on our internal dev server and it worked like a charm :)

    October 13th, 2008 | #

  3. TechnoBuddhist says

    Thx!! Works like a dream!!

    Just need to try and get it to work with java-php-bridge.

    October 21st, 2008 | #

Leave a comment

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad:

Comments for this post will be closed on 20 December 2008.

RSS feed for these comments.

With many thanks to Kaushal Sheth
`