Search |
|||
Cay Horstmann's blogRunning PHP Apps on GlassFishPosted by cayhorstmann on December 9, 2009 at 8:57 PM PST
For the upcoming semester, I want to run a learning management system into which I can integrate an experimental feature for evaluating student programs. It needs to be open source so that I can modify it. I was first going to go with Sakai, which is based on Java, but just about everyone else is going to Moodle, and there are reasons for that. The problem is, Moodle is written in PHP, and I am not a LAMP guy. I run Java, PostgreSQL, OpenSolaris, and GlassFish. (Thanks Sun for donating the server!) What's a JPOG guy going to do? In this blog, I show three ways of running a PHP application on GlassFish. These all work with GlassFish and Moodle. Quercus
I had my doubts, but Moodle is listed as a supported application and indeed, it worked like a charm. Installation couldn't be simpler. Download Moodle and Quercus: wget http://download.moodle.org/download.php/direct/stable19/moodle-weekly-19... wget http://caucho.com/download/quercus-4.0.2.war Unzip somewhere, superimposing the Quercus and Moodle trees, so that the Moodle tree wins out with cd /somewhere mkdir moodle cd moodle unzip ~/quercus-4.0.2.war tar xvfz ~/moodle-1.9.7.tgz mv moodle/* . rmdir moodle Do the other things you need to do for Moodle: create a Deploy, using directory deployment. That way, you can keep making changes to the Moodle PHP files, which is the modus operandi when adding themes or plugins. asadmin deploy /somewhere/moodle (This is with GlassFish v3.) Now point your browser to There are ominous warnings about missing xml-rpc and ssl libraries, but they haven't caused me any problems yet. Overall, this is very impressive and the simplest way of getting going for a non-PHP person. PHP/Java Bridge
The installation procedure is similar. Download the latest PHP/Java Bridge binary from here. Download Moodle. Extract them into the same directory. Then you need to edit <init-param> <param-name>php_include_java</param-name> <param-value>Off</param-value> </init-param> (Thanks to Peter from the project mailing list for this tip!) Again, run asadmin deploy /somewhere/moodle and point your browser to The advantage of using the bridge is that you are using genuine PHP, so there isn't any potential incompatibility issue. (The Quercus people will tell you that this is also a disadvantage—PHP is more prone to attacks than Java, and it is not all that fast.) It is worth noting that both with Quercus and the PHP/Java Bridge, you can make Java calls from PHP code, which can come in handy if you want to extend the capabilities of your PHP program without the indignity of having to code in PHP. jFastCGI
Check out the latest code from SourceForge and build it. Curiously, the Ant script assumes that you have the servlet library on the global class path: cd ~ svn co https://jfastcgi.svn.sourceforge.net/svnroot/jfastcgi/trunk jfastcgi export CLASSPATH=.:/path/to/glassfishv3/glassfish/modules/javax.servlet.jar cd jfastcgi/ant ant Now unzip Moodle somewhere and turn it into a web application like this: mkdir -p /somewhere/moodle/WEB-INF/lib cp ../dist/jFastCGI.jar /somewhere/moodle/WEB-INF/lib cp ../lib/*.jar /somewhere/moodle/WEB-INF/lib Make a file <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <servlet> <servlet-name>FastCGI</servlet-name> <servlet-class>net.jr.fastcgi.FastCGIServlet</servlet-class> <init-param> <param-name>server-address</param-name> <param-value>localhost:6667</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>FastCGI</servlet-name> <url-pattern>*.php</url-pattern> </servlet-mapping> </web-app> Run php-cgi -b6667 (The docs recommend port 6666, but for some reason, that is taken on my machine.) Deploy the directory to GlassFish, and it works. SummaryI am a Java guy and build my applications with JSF and JPA. But there is no denying that there is a lot of PHP code out there that does useful stuff. If you need to host a PHP app with your Java apps, you don't have to drink the LAMP Kool-Aid. There are multiple ways of making this work with GlassFish, which gave me the courage to go with one of them and use the others as a fallback. »
Related Topics >>
Blogs Comments
Comments are listed in date ascending order (oldest first)
|
CategoriesArchivesDecember 2009
November 2009 October 2009 September 2009 August 2009 July 2009 June 2009 May 2009 April 2009 February 2009 January 2009 December 2008 November 2008 October 2008 September 2008 July 2008 June 2008 May 2008 April 2008 March 2008 January 2008 December 2007 August 2007 July 2007 June 2007 May 2007 April 2007 January 2007 October 2006 September 2006 August 2006 July 2006 June 2006 Recent Entries |
||
|
|