Local Navigation

PHP/JavaBridge and WebSphere 3: Adding Drupal to the Mix

The steps to integrate PHP and Drupal with Apache are well-documented in an IBM tutorial for Windows and Linux.  You'll need to register for the IBM website to view it, but it's well worth the few minutes it takes.  Note that these installation tutorials are part of a very good larger series on Drupal from IBM, available here as an RSS feed.

Before you begin the tutorial I'd suggest you back up your Apache configuration, in case something breaks in the course of Drupal and PHP integration.

Go through the tutorial, installing PHP, MySql, Drupal, etc. but skipping the step to install Apache, as you've already installed Apache or IHS in Second Steps.  Of course you can install or reference a database of your choice, but I think it's better to keep things simple at this stage and use MySql, switching out the data layer at a later stage of development.

Configure Apache, MySQL and PHP per the tutorial.  In essence this involces:

  1. Pointing Apache at the Drupal environment.  You'll have imported Drupal in an earlier tutorial step.  Note that Eclipse 3.3 with the PDT tools works fine, as does IBM Rational RAD without PDT.  Sorry, no PDT for IBM RAD in August 2007.
  2. Enabling PHP to see and appropriately interpret the Drupal files

For the record, my Apache httpd.conf looks like this at the end:

PHPIniDir "C:\\PHP\\"
LoadModule php5_module "C:\\PHP\\php5apache2.dll"
# Include virtual hosts
Include "C:/apache2/Apache2/conf/vhosts.d/drupal.development.conf"
# End virtual hosts
# Begin IBM Plugin for WebSphere
LoadModule was_ap20_module "C:\Program Files\IBM\WebSphere\Plugins\bin\mod_was_ap20_http.dll"
WebSpherePluginConfig "C:\Program Files\IBM\WebSphere\Plugins\config\localApache\plugin-cfg.xml"
# End IBM Plugin for WebSphere

My drupal.development.conf file defining the drupal virtual host looks like:

ServerName drupal.development
DocumentRoot "C:\data\drupal\drupal_development\drupal_development\drupal-5.2"
<Directory "C:\data\drupal\drupal_development\drupal_development\drupal-5.2">
AllowOverride All
Order Deny,Allow
Deny from All
Allow from
CustomLog "C:\apache2\Apache2\logs\drupal_development-access.log" common
ErrorLog "C:\apache2\Apache2\logs\drupal_development-error.log"

You need to modify your hosts file to use drupal.development to resolve to       localhost development drupal.development

Finally, the PHP.ini mods will look something like this:

; Windows: "\path1;\path2"
include_path = ".;c:\php\includes;c:\Data\drupal\drupal_development\drupal_development\drupal-5.2"

Configure your site per the tutorial.  When you're done you should see a standard drupal home page.

Enable PHP to use the Java Integration Include

The Java.inc file running in your JavaBridge is the key to PHP integration.  In order for an external PHP instance to correctly access the bridge the session needs to execute the instance of Java.inc that is running on the bridge using http.

I'd prefer this were externally configurable, but don't know enough about the bridge yet to do so.

PHP blocks http access to files out of the box as a security measure.  You'll need to relax that prohibition to use the bridge, per the section below:

; Fopen wrappers ;
; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
allow_url_fopen = On
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
allow_url_include = On

We'll need to find a better way later!

Ensure Integration with Java is Intact

Let's make sure we did no harm.  You backed up your old Apache configuration, right!

  1. Create a file in the Drupal installation root called sessionPeek.php. 
    'allow_url_fopen', 'on');
    $session = java_session();
    <TITLE>JSP session peeking</title>
    if (is_null($session->get("counter"))) { // If we're starting the counter, start it distinctively
       $session->put("counter", new Java("java.lang.Integer", 5));
    $counter = $session->get("counter");
     "I'm peeking into a Java session from PHP to dredge up a counter<br/>";
     "Hello, the hidden number is ", $counter->toString() ;

    As you see the code executes a require_once on the magical Java.inc in the bridge which gives us the ability to access a Java session.  The remainder of the code prints out the value of a session counter. 

  2. Our test will use a JSP in the JavaBridge to set a session counter, and our sessionPeek.php running in pure PHP to access and print out the counter.  Notice that the sessionPeek running outside the bridge runs about five times faster than the equivalent code in the bridge.  I'm guessing that the Apache/PHP collaboration is way faster than the JavaBridge/PHP collaboration.  The sessionPeek only uses the JavaBridge for session access, which is much more efficient than using JavaBridge for the whole PHP engine.

Bring up the JavaBridge examples page as in Part 2, using a url like:

  1. The IBM WebSphere plugin should intercept the call, notice the JavaBridge URL pattern and route to the WAS server, which will return the JavaBridge Examples page:

  2. First click on the Execute link for Session Sharing.  This PHP page will create and print a Java session counter using PHP running inside the JavaBridge.  Note how long it takes ... about 5 seconds on my system

  3. Next click on the JSP Page link you see above.  This will access the Java session counter, increment it, and print it.  Note how fast it is; under 100ms on my system:

  4. Now, instead of using the PHP Page link to bounce back to the bridged PHP session page, enter the URL to run our sessionPeek.php script from outside of the bridge.  sessionPeek will, from outside the bridge, use the bridge to obtain access to the Java session, peek at the counter, then print it.  The URL will be:
    and the result should be very fast (under 1 second on my system) and look like this:

That's it.  We've created a Java session variable from PHP, incremented it using JSP and then accessed it from outside the bridge using PHP.

On to Drupal integration