PHP Remote Debugging on Zend Server for IBM i using xdebug and Netbeans

This is a guide on how to setup xdebug on Zend Server for IBM i to use with any IDE w/ a xdebug client such as Netbeans.

Step 1  Get xdebug.so and put it on the IBM i IFS

Zend Server usually already has the file so just check that its in the

/usr/local/zendphp7/lib/php_extensions

If its not there, you can either compile your own xdebug.so by downloading the source from http://xdebug.org/ or you can just download this xdebug.so file.   Once you have the .so file you upload it to the IFS directory above.  Note on older versions of ZS the location might be:

/usr/local/zendsvr/lib/php_extensions

/usr/local/zendsvr6/lib/php_extensions

Step 2 – Setup php.ini file and other config files

You’ll also have to set

output_buffering = Off

in the php.ini.  The default for this is output_buffering=4096.  Make sure the default is commented out.

PHP.ini location: /usr/local/zendphp7/etc/php.ini

Disable Zend Debugger and Zend Optimizer

You’ll have to turn off Zend Debugger and Zend Optimizer as these files will interfere with xdebug.  To turn off this go to /usr/local/zendphp7/etc/conf.d/debugger.ini and comment out

; zend_extension_manager.dir.debugger=/usr/local/zendphp7/lib/debugger

with  a semi colon at the beggining of the line.  In older versions of Zend Server you may have to comment out optimizerplus.ini in the same directory

;zend_extension_manager.dir.optimizerplus=/usr/local/zendphp7/lib/optimizerplus

in the xdebug.ini file in the directory /usr/local/zendphp7/etc/conf.d modify it to look like the xdebug.ini below.

Step 3 – Restart Apache

On the i5/as400/iseries type:

Go ZENDPHP7/ZSMENU

Option 5 – Service Management menu

Option 6 – Stop Apache server instances

Option 5 – Start Apache server instances

or do it at https://myibmi:2001/HTTPAdmin

Step 4 – Setup xdebug client in Netbeans

Right click a project and go to project properties.  In sources, set the Web Root to the local files that map to your Web Root on the i5 (/www/zendphp7/htdocs/{myapp}).   In the Run Configuration, set up the Project URL and the index file to point to your starting index.php file.  On the toolbar menu click Tools->Options ->PHP tab-> Debugging sub tab.  At this location you can set the debugger port, session ID, if it should stop at the first line of a file, what URLs were requested and to show the debugger console.

netbeans-php-debugging-options.png

Step 5 – Launch Debugger

You lauch the debugger by pressing CTRL+F5 or by clicking the debug icon.

debug icon netbeans.png

Hopefully if everything was setup right you’ll be able to start the debugger and Netbeans will open your website up in a browser and then connect to xdebug on the server.  The way it works is the client sends the request on port 80 and then the server and the client communicate over port 9000 or the port you selected.  You’ll get all the Variables, Call stack and be able to step through the PHP code and set up Break points through out the file. If your having troubles getting this working let me know.  Running phpinfo() will also give you an idea if you’ve correctly installed xdebug.

Misc. Tips

1. You may have to move the CW wrapper for the old i5 toolkit into your project file.  You can find those files in the /usr/local/zendphp7/share/ToolkitAPI folder on the IFS.

2. You can use xdebug’s wizard that uses your phpinfo and helps you detect and install xdebug – http://xdebug.org/wizard.php

3. If your looking to compile php on the iseries this site might help – http://www.deloli.net/distrib.php

4. Netbeans wiki on how to configure xdebug  – http://wiki.netbeans.org/HowToConfigureXDebug

What phpinfo() will display about xdebug.

 

Advertisements

15 thoughts on “PHP Remote Debugging on Zend Server for IBM i using xdebug and Netbeans

    1. David Dressler Post author

      I agree Kent. I wouldn’t recommend doing this in production. I haven’t seen serious slow down on our development system but im sure if your a bigger shop with more users you’ll want zend optimizer on in production. I rarely ever have to debug in Production.

      Reply
      1. Naveen Dronavalli

        Hi David,

        Do you from where I can download xdebug.so that is compatible with PHP 5.4? I tried to download the source and compile my self on system i but ran into couple of issues.

        When try PHPIZE, getting an error saying /usr/local/bin/sed is not found and autoconf is not loacated.

  1. Jane Harris

    No joy here. I start the debug, but it doesnt break on the break points.

    PHPINFO shows XDEBUG version 2.1.2 installed

    netbeans-xdebug says it is running.

    any help much appreciated

    Reply
    1. David Dressler Post author

      Jane,

      I had the same issue before. I had to make sure all the code I work with was inside my Netbeans project. I was missing the CW wrapper files that are used to wrap over the old i5 toolkit. I had to move the ToolkitAPI (CW wrapper files) folder to my project so that Netbeans could find those files when its needed. You should check to see if you have any files that are on the server that are being accessed but are not in your local Netbeans project.

      On Netbeans, go to tools-> options-> PHP -> debugging, turn on these 3 options: stop on First Line, show requested URLs and show debugger console. Then press Ctrl+F5 to start a debug session. Click the window in Netbeans that says “Call Stack”. Then walk through the code by pressing F8 to step over, or F5 to continue. Because we selected “stop on first line” the debugger will stop at the beginning of each file its about to use. Check the call stack and see if the file its on is in your project. If its not you’ll see file://{path to file on server}, if its in your project you’ll see C:\{path to file on local computer}

      Hope this helps.

      Reply
  2. Jane Harris

    Thanks David – still no joy. when I start the project debug, even though I said ‘stop on first line’ it never gets into the debug. none off the debug command keys, f5, f8 etc are enabled.

    Thanks for your help.

    Reply
  3. David Dressler Post author

    Hmmm… It seems Netbean’s xdebug client never properly connects to the Server. I’m assuming this is a network/firewall issue. Maybe port 9000 is being blocked by a firewall on your PC, or on the Server?

    This is a nice diagram of how xdebug connects to better illustrate how xdebug tries to connect – http://xdebug.org/docs/all#communication

    Reply
  4. Jane Harris

    netbean-xdebug shows running in the ide, also on the PC it is listening on port 9000 – TCP 0.0.0.0:9000 0.0.0.0:0 LISTENING
    this is all on a local network, no firewall inbetween. I’ve also switched off the windows firewall without any success. the IBM i does not report any errors and also shows a connection with netstat 10.0.0.102 9000 26204 000:00:18 FIN-wait-2

    Thanks once again.

    Reply
  5. David Dressler Post author

    Hmmm.. I’m getting really stumped here…. Maybe check to make sure Zend Debugger and Zend Optimizer are disabled.

    What version of Zend Server, OS and Netbeans are your running? I’m running Zend Server 5.6 for IBM i, windows xp 64 bit and Netbeans 7.1

    Reply
  6. Jane Harris

    Our setup is very similar: Zend Server 5.6 for IBM i, Netbeans 7.1.2 & Windows 7 64bit.

    I have commented out the following lines, in the ini files, to stop the optimizer:

    ;zend_extension_manager.dir.optimizerplus=/usr/local/zendsvr/lib/optimizerplus

    ;zend_extension_manager.dir.debugger=/usr/local/zendsvr/lib/debugger

    Your help is much appreciated
    Jane

    Reply
  7. Vicki Wilson

    Close – but not quite there.
    Old post – but the configuration helped me half the way. I’m not using netbeans – but I am using PDT in Eclipse. I can see the debug stepping through in the debug view – but it isn’t stopping on my breakpoints.
    Any thoughts? Resources to ask?
    Thanks.
    Vicki

    Reply
    1. PHPDave Post author

      Hi Vicki,

      I’d look into making sure you have the same source code in your project as whats on the server. I think the IDE might be missing the code path and thats why it doesn’t know how to get to your breakpoint. This is just a guess. I don’t know many other resources using xdebug. You could look into using phpdbg http://phpdbg.com/ , Z-Ray, or Zend Debugger. If you do try those debuggers out I’d love to hear how you like them.

      Best of Luck

      Dave

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s