The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


100% Java Quercus PHP engine running in GlassFish Java EE 5 Application Server...

Posted by ludo on March 9, 2007 at 9:53 PM PST
Bonjour, Comment Java?

I spent a few hours playing with  Quercus, the  Caucho Technology's 100% Java implementation of PHP 5, trying to make it run with the GlassFish Java EE 5 application Server. Quercus comes with many PHP modules and extensions like PDF, PDO, MySQL, and JSON.
Download the quercus engine war file. Unzip this quercus-3_1-snap.war war file, and copy the 2 files quercus.jar and resin-util.jar from the WEB-INF/lib archive directory to the GlassFish lib/addons directory (GLASSFISHINSTALLDIR/lib/addons) If the GlassFish Application Server is not using JDK 1.6, but only JDK 1.5, you'll also need the javax.scripting.* JSR 223 apis. You can get the jsr223-api.jar file from the Phobos CVS repository, and store it as well under the GLASSFISHINSTALLDIR/lib/addons directory.

One final configuration file for php is needed. It is called GLASSFISHINSTALLDIR/domains/domain1/config/php.ini and should contain as a minimum this property value:

default_mimetype=text/html

Nothing more, nothing less. (If you are using a different GlassFish domain, just put this php.ini file in the domain's config directory.

So to recap, this is the files you should have on disk for configuring a PHP engine with GlassFish:

  • GLASSFISHINSTALLDIR/
    • lib/
      • addons/
        • quercus.jar (taken from the quercus-3_1-snap.war)
        • resin-util.jar (taken form the quercus-3_1-snap.war)
        • jsr223-api.jar (taken from Phobos CVS repository)
    • domains/
      • domain1/
        • config/
          • php.ini that contains default_mimetype=text/html

That's it...

Now using your favorite IDE (vi, or NetBeans), you can create a simple Web Application, and what you need to do is declare the PHP engine as a servlet and the location of the php.ini file, as follow:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="2.5">
<description>Caucho Technology's PHP Implementation, Running on GlassFish Java EE 5</description>
<servlet>
<servlet-name>Quercus Servlet</servlet-name>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
<init-param>
<param-name>php-ini-file</param-name>
<!-- the following value is a file name relative to the config directory
of the running GlassFish domain
for example GLASSFISHINSTALLDIR/domains/domain1/config/ dir
the php.ini file contains:
default_mimetype=text/html
otherwise the current Quercus will give a NPE
(will be fixed soon from Caucho team)!-->
<param-value>php.ini</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>

Now you are all set: this Web App is PHP ready. Just Add PHP files under the web folder area, where you would put your JSPs files.

The simplest index.php can be:

<?php
echo "Hello World";
?>

If you want to test the Java interoperability, you can go wild and crazy with this:

<?php
  echo "Hello mom, look I have a date: ";
  $a = new java("java.util.Date", 123);
  echo $a->toString();
?>
Or even crazier, you can test that the Ajax jMaki project is working also in PHP applications, including the ones using the Quercus PHP pure Java engine running int he GlassFish Java EE 5 container...The sky is the limit.

A  complex PHP application  is MediaWiki.  Untar the mediawiki PHP application archive inside the WEB-INF area of your web application, and redeploy it (if you are using NetBeans, you have almost nothing to do as NetBeans does an update of the deployed build area when files are modified in the source area). Activate the Web Application at the correct URL to see if MediaWiki 1.9.3 home page is correct as below:

GlassFishPHPQuercus_html_72d1eeab.jpg

Here is the PHP index page...

<?php
# Initialise common code
require_once('./includes/WebStart.php' );

# Initialize MediaWiki base class

require_once("includes/Wiki.php" );

$mediaWiki = new MediaWiki();

wfProfileIn('main-misc-setup' );

OutputPage::setEncodings();
# Not really used yet


# Query string fields

$action = $wgRequest->getVal( 'action', 'view' );
$title = $wgRequest->getVal( 'title' );

$wgTitle = $mediaWiki->checkInitialQueries( $title,$action,$wgOut,
$wgRequest, $wgContLang );


if ($wgTitle == NULL) {
unset( $wgTitle );
}

#
# Send Ajax requests to the Ajax dispatcher.
#
if ( $wgUseAjax && $action == 'ajax' ) {   
require_once( $IP . '/includes/AjaxDispatcher.php' );
 
$dispatcher = new AjaxDispatcher();

$dispatcher->performAction();
$mediaWiki->restInPeace( $wgLoadBalancer );
exit;

}

wfProfileOut('main-misc-setup' );
# Setting global variables in mediaWiki

$mediaWiki->setVal('Server', $wgServer );
$mediaWiki->setVal('DisableInternalSearch', $wgDisableInternalSearch );

$mediaWiki->setVal('action', $action );
$mediaWiki->setVal('SquidMaxage', $wgSquidMaxage );
$mediaWiki->setVal('EnableDublinCoreRdf', $wgEnableDublinCoreRdf );
$mediaWiki->setVal('EnableCreativeCommonsRdf', $wgEnableCreativeCommonsRdf );
$mediaWiki->setVal('CommandLineMode', $wgCommandLineMode );
$mediaWiki->setVal('UseExternalEditor', $wgUseExternalEditor );
$mediaWiki->setVal('DisabledActions', $wgDisabledActions );

$wgArticle = $mediaWiki->initialize ( $wgTitle, $wgOut, $wgUser, $wgRequest );
$mediaWiki->finalCleanup( $wgDeferredUpdateList, $wgLoadBalancer, $wgOut );

# Not sure when $wgPostCommitUpdateList gets set, so I keep this separate from finalCleanup

$mediaWiki->doUpdates($wgPostCommitUpdateList );
$mediaWiki->restInPeace($wgLoadBalancer );
?>
The setup page as rendered with Pure Java Quercus PHP engine on GlassFish: (Sorry, I did not have the time to configure the MySQL database yet)

GlassFishPHPQuercus_html_m251ad121.jpg

For more info, read http://quercus.caucho.com/ and the documentation under http://quercus.caucho.com/quercus-3.1/index.xtp .

The pure Java PHP engine is still an Alpha version, so please try it, break it and give feedback. The list of PHP applications the caucho team will be testing is very impressive:

And do not forget that the Ajax jMaki project is PHP friendly, and JSP friendly, and Server Side JavaScript Phobos friendly...

A Plus,

Ludo

Related Topics >> Java Enterprise      
Comments
Comments are listed in date ascending order (oldest first)

today is some type of

today is some type of historical milestone for Java EE 6: This is Milestone 1 of NetBeans 6.8 and Java EE 6 support with the latest GlassFish v3 (build 57). The bundle is only 132Mb and contains everything you need to start with Java EE 6: the IDE, the Java EE 6 current runtime, the JavaEE 6 JavaDocs (for code completion), the JavaDB database, and very very cool features from the plaform or its implementation: online associate degrees AND Online degrees

Re

Thanks for sharing, been a reader for some time now, keep up the fantastic job! Wishing you the best new year to come. Aaron MN | web hosting

Java platform can be

Java platform can be connected with oracle because if i need more stable network then i need to use Oracle. e lottery

This is Milestone 1 of

This is Milestone 1 of NetBeans 6.8 and Java EE 6 support with the latest GlassFish v3 (build 57). The bundle is only 132Mb and contains everything you need to start with Java EE 6: the IDE, the Java EE 6 current runtime, the JavaEE 6 JavaDocs (for code completion), the JavaDB database Bollywood Stars Photos | Ayesha Takia Images | Kareena Kapoor Images

Mobile applications are

Mobile applications are mostly done into the JE platform. Marketing For Dentists

Yes, certainly a milestone -

Yes, certainly a milestone - well done to all those involed. cheap auto insurance.

"today is some type of

"today is some type of historical milestone for Java EE 6: This is Milestone 1 of NetBeans 6.8 and Java EE 6 support with the latest GlassFish v3 (build 57). The bundle is only 132Mb and contains everything you need to start with Java EE 6: the IDE, the Java EE 6 current runtime, the JavaEE 6 JavaDocs (for code completion), the JavaDB database, and very very cool features from the plaform or its implementation" - I agree about get ex back and get my ex back

Hi Ludo, I tried taking it

Hi Ludo, I tried taking it for a spin, but I couldn't get facelet page editing to do anything useful. The editor insisted that the facelets pages were plain HTML files. Is there some secret switch? Thanks, Cay Diploma Programs AND Online Certificate Program AND Degree Programs

very interesting ! Thank you

very interesting ! Thank you for this great article ! By the way, i love Fashion designers and Hedi Slimane !

Java apps for mobile games i

Java apps for mobile games i need J2ME J2EE platform No Prescription Online Pharmacy

Hi there!

Good instructions and it's quite interesting. Submit free articles at http://www.articlemonkeys.com/

Java platform can be

Java platform can be connected with oracle because if i need more stable network then i need to use Oracle. ben 10: alien force season 3 episode 13 | dollhouse season 2 episode 11 | ghost adventures season 3 episode 10

Yeha very Useful information

Yeha very Useful information , this is both good reading for, have quite a few good key points, and I learn some new stuff from it too, thanks for sharing your information. handbags wholesale handbags

Finally, an issue that I am

Finally, an issue that I am passionate about. I have looked for information of this caliber for the last several hours. Your site is greatly appreciated. copy xbox 360 games|wow leveling guide|watch satellite tv on pc|xbox 360 repair guide|Perfect Golf Swing|Joana's Horde Leveling Guide Review|warcraft millionaire|Game Copy Pro Review|How to Make Money on eBay|legitimate paid surveys

RE: Finally, an issue that I am

This is Milestone 1 of NetBeans 6.8 and Java EE 6 support with the current GlassFish v3 build 57 Thesis | Dissertation | Essay | Assignment

Quercus

Wow, that's awesome, I am addicted using Quercus, I used it on many sites and it has provided me with great features. Just read you post about Quercus and I decided to add my experience. Now it is becoming more popular among the MediaWiki 1.9.3 but 2.0 is great. Thanks for sharing. finger pulse oximeter

ClassNotFoundException

Hi: I am using Sun GlassFish Enterprise Server v2.1.1 on JDK1.5.0_17
i had copied following files into GLASSFISHINSTALLDIR/lib/addons
+ quercus.jar (taken from the quercus-3_1-snap.war)
+ resin-util.jar (taken form the quercus-3_1-snap.war)
+ jsr223-api.jar (taken from Phobos CVS repository)

and i have the php.ini
* domains/
o domain1/
+ config/
# php.ini that contains default_mimetype=text/html

but when i deploy the web application which contains index.php,i can't visit it due to following ClassNotFoundException exception. how can i fix it?
java.lang.ClassNotFoundException: com.caucho.quercus.servlet.QuercusServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1578)
at org.apache.catalina.core.StandardWrapper.loadServletClass(StandardWrapper.java:1273)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1049)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:848)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1093)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:291)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:666)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:597)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:872)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.portunif.PortUnificationPipeline$PUTask.doTask(PortUnificationPipeline.java:382)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:264)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)

BTW:i tried to put the three jars(quercus.jar...) into web application's WEB-INF\lib directory. it works, i can see the "hello world" when i visit the web application。