Thursday Aug 23, 2007

jMaki, PHP and GlassFish - again using Caucho Quercus

jMaki is a light-weight framework for build Web 2.0 applications. It provides support for multiple languages - Java (1, 2, 3, 4, 5, 6) , PHP, Ruby (1, 2), Phobos (1). The numbers in parentheses indicate the entries that I've created showing jMaki support for that language. As evident, I've not created a single entry for PHP yet. This entry is going to change that :)

This entry shows how to deploy a jMaki-enabled PHP web application in GlassFish. It builds upon an earlier entry that showed how to deploy a simple PHP application in GlassFish.

  1. PHP-enable GlassFish and verify it's working correctly following these steps.
  2. Build, Install and Run a simple jMaki/PHP sample
    1. Download and Unzip the contents of jMaki/PHP release (0.9.7.2 as of this writing). This creates "jmaki-php-0.9.7.2\\jmaki-php" in the current directory.
    2. Go to "jmaki-php-0.9.7.2\\jmaki-php\\core" and invoke "ant". This creates "dist\\jmaki-core.zip".
    3. Unzip the contents of "jmaki-core.zip" under the "web" directory of the project created in the link followed from first step.
    4. Redeploy your project and your first jMaki widget in a PHP page deployed on GlassFish is now available at "http://localhost:8080/hellophp/jmaki-core/index.php".

      If you look at "index.php" in the IDE, the page contains the following code fragments:

      <?php addWidget("hello"); ?>

      <?php addWidget( array( "name" => "hello2",
                              "args" => "{name: 'Duke'}")
      ); ?>


      If you look at the source code of the generated page, the PHP code is converted to JavaScript code as shown below:

      <link type='text/css' rel='stylesheet' href='http://localhost:8080:8080/hellophp/jmaki-core/resources/hello/component.css'></link>
      <script type='text/javascript' src='http://localhost:8080:8080/hellophp/jmaki-core/resources/hello/component.js'></script>
      <script type='text/javascript'>
        jmaki.addWidget({uuid:"hello_2",
                         name:"hello",
                         widgetDir:"http://localhost:8080:8080/hellophp/jmaki/resources/hello",
                         script:"http://localhost:8080:8080/hellophp/jmaki/resources/hello/component.js"});
      </script>

      and

      <link type='text/css' rel='stylesheet' href='http://localhost:8080:8080/hellophp/jmaki-core/resources/hello2/component.css'></link>
      <script type='text/javascript' src='http://localhost:8080:8080/hellophp/jmaki-core/resources/hello2/component.js'></script>
        <div id="hello2_3" class="hello2"></div>
        <script type='text/javascript'>
        jmaki.addWidget({uuid:"hello2_3",
                         name:"hello2",
                         widgetDir:"http://localhost:8080:8080/hellophp/jmaki-core/resources/hello2",
                         args: {name: 'Duke'},
                         script:"http://localhost:8080:8080/hellophp/jmaki-core/resources/hello2/component.js"});
      </script>


      Notice the JavaScript code shows the host + port as "localhost:8080:8080". This issue is followed here.
  3. Build, Install and Run a slightly advanced sample.
    1. Go to "jmaki-php-0.9.7.2\\jmaki-php\\samples\\loadtable" and invoke "ant". This creates "dist\\jmaki-loadtable-php-0.9.7.2.zip".
    2. Unzip the contents of this zip file under the "web" directory of your project.
    3. Redeploy you project and the sample is now deployed at "http://localhost:8080/hellophp/web/jmaki-loadtable/index.php".

      This sample shows a Dojo DataTable loading static data. The code fragment to add the widget to the page is:

      <?php
        addWidget('dojo.table', null, null, null, "tabledata.json");
      ?>


      You can look at the generated source using "View Source". A nice twist to try is to dynamically load the data from a database using JPA as shown here.

None of the samples that use XMLHttpProxy (rssData, cl-mashup and mapit) will work because I could not find XSLT extension for Quercus. This issue is followed here. Other users have asked similar question with no clear answer.

Technorati: jmaki php glassfish web2.0 caucho quercus

PHP in GlassFish using Caucho Quercus

Quercus is Caucho Technology's 100% Java implementation of PHP 5. Ludo described the steps to deploy PHP web applications on GlassFish. Caucho has released a new version of Quercus since then. This blog entry is an update to the steps described earlier.

  1. First, PHP-enable GlassFish.
    1. Unjar quercus-3.1.1.war and copy the JAR files in "WEB-INF/lib" directory to "GLASSFISH_HOME/domains/domain/lib" directory. That's it! Although the original entry requires to copy the JARs in "GLASSFISH_HOME/lib/addons" directory but that didn't work.
  2. Create a PHP web application
    1. Create a new Web application project, lets say "hellophp", using NetBeans IDE and choose GlassFish as the server.
    2. Replace the contents of "web.xml" with the following fragment:

      <?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>
        </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>


      This will declare PHP engine as the servlet.
    3. Add a new page "index.php" in "Web pages" folder. The contents of the page are:

      <?php
      echo "Hello World!";
      phpinfo();
      ?>

      This page prints "Hello World!" on the browser and some configuration settings of PHP. The directory structure of the created project looks like:

      META-INF/
      META-INF/MANIFEST.MF
      WEB-INF/
      WEB-INF/classes/
      WEB-INF/sun-web.xml
      WEB-INF/web.xml
      index.jsp
      index.php

      Notice, "index.jsp" is only a template file to get started with JSPs and "sun-web.xml" is GlassFish-specific deployment descriptor. These files are not required for this PHP application although it does not hurt to leave them in the webapp as well.
  3. Deploy the application by right-clicking on the project and selecting "Deploy Project". Your first PHP application in GlassFish is now deployed at "http://localhost:8080/hellophp/index.php".

Now that you have verified that your GlassFish is ready to host PHP applications, try the different applications that are described in Ludo's blog.

Technorati: php glassfish caucho quercus

About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today