Shindig on PHP – Setting up a Debug Environment


By Anash P. Oommen


 

Overview

 

Shindig is a new project in the Apache Software Foundation incubator and is an open source implementation of the OpenSocial specification and gadgets specification. Details of Shindig can be found at http://incubator.apache.org/shindig/

 

Shindig is currently available in Java and PHP. The following article explains how to setup a debug environment for the PHP version of Shindig on your windows machine.

Setting up a development environment

 

As one starts serious development with shindig, a development environment becomes indispensable. I have chosen to setup the development environment using PhpEd, an IDE for PHP.

 

PhpEd is a commercial PHP IDE available from http://www.nusphere.com. You can download a trial version of this IDE from http://www.nusphere.com/download.php.ide.htm.

 

Run the setup and follow the instructions to complete the setup.

Setting up remote debugging

 

PhpEd allows you to debug a website that is hosted on Apache. To enable this, one has to do the following steps:

 
 

  1. Download dbg-wizard.php from http://www.nusphere.com/products/dbg_wizard_download.htm. This page will make the configuration process easy.
  2. Copy dbg-wizard.php to your htdocs/shindig/php folder.
  3. Modify the contents of your .htaccess file at htdocs/shindig/php as follows 

<IfModule mod_rewrite.c>

      RewriteEngine On

      RewriteCond %{REQUEST_FILENAME} !-f

      RewriteCond %{REQUEST_FILENAME} !-d

      RewriteRule (.*) index.php [L]

</IfModule>
 
    4.   Open a web browser and navigate to http://localhost/shindig/php/dbg-wizard.php. If everything goes well, you should see a page like this:

 
Towards the end of this page, you should find the configuration instructions. But for ease of discussion, I will list them below:
  • Enable PHP Debugger on our installation. To do this, go to C:\Program Files\nusphere\phped\debugger\server\Windows\x86. Copy the file php_dbg.dll-5.2.x to C:\Program Files\xampp\php\ext. 
  • Now, open the file C:\Program Files\xampp\apache\bin\php.ini in Notepad. Look for the following lines:
zend_extension_ts = "C:\Program Files\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll"
 
Comment this line by putting a ; before the line.
 
  • Add the following line just above the line we commented:
zend_extension_ts=C:\Program Files\xampp\php\ext\php_dbg.dll-5.2.x
 
  • Add the following lines at the end of php.ini.

[debugger]
debugger.hosts_allow= 127.0.0.1 localhost
debugger.hosts_deny=ALL
debugger.ports=7869, 10000/16
 
  • Now save and close php.ini. Restart Apache.
  • Now navigate to your phpinfo() page on http://localhost. If things went fine, you should see a page as follows:
 
Note that the Zend Engine 2 box says, “Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies with DBG v3.2.14, (C) 2000,2008, by Dmitri Dmitrienko”, which tells us that DBG has been activated in PHP. 

Setting up a Workspace

 

Open PhpEd. Create a new workspace, and a new project in it. The new project window should show up like this:
 
 

Enter the following values in the various text boxes:

 

Root directory: C:\Program Files\xampp\htdocs\shindig\php\

Run Mode: HTTP Mode (3-rd party WEB server)

Root URL: http://localhost/shindig/php/

Remote Root Directory: C:\Program Files\xampp\htdocs\shindig\php\

 

Now save your project and workspace.

 

We can start debugging Shindig from the SampleContainer page - http://localhost/shindig/php/gadgets/files/samplecontainer/samplecontainer.html. However, PHPEd does not debug files with .html extension, and to make things worse, there is no physical file at the location

htdocs/shindig/php/gadgets/files/samplecontainer/samplecontainer.html. So, to allow debugging the samplecontainer page, we make a few adjustments to the Shindig files.

 
    1.  Create a new file named start.php in htdocs/shindig/php folder and add the following lines:

 

<html>

    <head>

        <title></title>

    </head>

    <body>

        <a href="http://localhost/shindig/php/gadgets/files/samplecontainer/samplecontainer.html">Launch Container</a>

    </body>

</html>

 

As you might note, this is a simple html with a link to the samplecontainer page.

 

    2.   Start debugging the start.php that we just created. Once the page loads, click the “Launch Container” link.

PhpEd should now start debugging index.php, as shown below (the line highlighted in blue color)

 

 

By default, PhpEd uses an embedded browser for debugging, but you can change this option if you want to use say, Firefox for debugging, as shown below: