GlassFish, PHP and WordPress
Wednesday, June 18, 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:
1
2
3
4
5
6
7
8
9
10
11
12
<servlet>
<servlet-name>Quercus Servlet</servlet-name>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
<init-param>
<param-name>ini-file</param-name>
<param-value>WEB-INF/php.ini</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
If you’d like, you can also add index.php to the welcome file list:
1
2
3
4
5
6
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.php</welcome-file>
</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!