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.
;Turn off zend debugger in /usr/local/zendphp7/etc/conf.d/debugger.ini | |
;zend_extension_manager.dir.debugger=/usr/local/zendphp7/lib/debugger |
;Turn off output_buffering in php.ini | |
;output_buffering=4096 | |
output_buffering = Off |
;Enable xdebug in the /usr/local/zendphp7/etc/conf.d/xdebug.ini file: | |
; Xdebug Configuration [xdebug] | |
zend_extension=/usr/local/zendphp7/lib/php_extensions/xdebug.so | |
xdebug.remote_enable=1 | |
;remote_host limits connection to the 1 ip address specified. To find your ip on windows run ipconfig /all | |
;xdebug.remote_host=<client's ip address> | |
xdebug.remote_port=9000 | |
xdebug.idekey = "NETBEANS" | |
;Set the url with ?XDEBUG_SESSION_START=PHPSTORM and set a header Cookie: XDEBUG_SESSION_START=NETBEANS | |
xdebug.remote_autostart = 1 | |
xdebug.remote_handler=dbgp | |
xdebug.remote_mode=req | |
; remote_connect_back allows for multiple connections from different IPs. This is great for situations in which multiple developers will be developing on the same instance. | |
xdebug.remote_connect_back = 1 |
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.
Step 5 – Launch Debugger
You lauch the debugger by pressing CTRL+F5 or by clicking the debug icon.
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.
Output of phpinfo() when xdebug is enabled | |
xdebug | |
xdebug support enabled | |
Version 2.5.1 | |
IDE Key NETBEANS | |
Supported protocols Revision | |
DBGp – Common DeBuGger Protocol $Revision: 1.145 $ | |
Directive Local Value Master Value | |
xdebug.auto_trace Off Off | |
xdebug.cli_color 0 0 | |
xdebug.collect_assignments Off Off | |
xdebug.collect_includes On On | |
xdebug.collect_params 0 0 | |
xdebug.collect_return Off Off | |
xdebug.collect_vars Off Off | |
xdebug.coverage_enable On On | |
xdebug.default_enable On On | |
xdebug.dump.COOKIE no value no value | |
xdebug.dump.ENV no value no value | |
xdebug.dump.FILES no value no value | |
xdebug.dump.GET no value no value | |
xdebug.dump.POST no value no value | |
xdebug.dump.REQUEST no value no value | |
xdebug.dump.SERVER no value no value | |
xdebug.dump.SESSION no value no value | |
xdebug.dump_globals On On | |
xdebug.dump_once On On | |
xdebug.dump_undefined Off Off | |
xdebug.extended_info On On | |
xdebug.file_link_format no value no value | |
xdebug.force_display_errors Off Off | |
xdebug.force_error_reporting 0 0 | |
xdebug.halt_level 0 0 | |
xdebug.idekey NETBEANS NETBEANS | |
xdebug.max_nesting_level 256 256 | |
xdebug.max_stack_frames -1 -1 | |
xdebug.overload_var_dump 2 2 | |
xdebug.profiler_aggregate Off Off | |
xdebug.profiler_append Off Off | |
xdebug.profiler_enable Off Off | |
xdebug.profiler_enable_trigger Off Off | |
xdebug.profiler_enable_trigger_value no value no value | |
xdebug.profiler_output_dir /tmp/ /tmp/ | |
xdebug.profiler_output_name cachegrind.out.%p cachegrind.out.%p | |
xdebug.remote_addr_header no value no value | |
xdebug.remote_autostart On On | |
xdebug.remote_connect_back On On | |
xdebug.remote_cookie_expire_time 3600 3600 | |
xdebug.remote_enable On On | |
xdebug.remote_handler dbgp dbgp | |
xdebug.remote_host localhost localhost | |
xdebug.remote_log no value no value | |
xdebug.remote_mode req req | |
xdebug.remote_port 9000 9000 | |
xdebug.scream Off Off | |
xdebug.show_error_trace Off Off | |
xdebug.show_exception_trace Off Off | |
xdebug.show_local_vars Off Off | |
xdebug.show_mem_delta Off Off | |
xdebug.trace_enable_trigger Off Off | |
xdebug.trace_enable_trigger_value no value no value | |
xdebug.trace_format 0 0 | |
xdebug.trace_options 0 0 | |
xdebug.trace_output_dir /tmp/ /tmp/ | |
xdebug.trace_output_name trace.%c trace.%c | |
xdebug.var_display_max_children 128 128 | |
xdebug.var_display_max_data 512 512 | |
xdebug.var_display_max_depth 3 3 |
BTW this should probably only be done in a development LPAR as turning off Optimizer + will have very serious negative impacts on performance.
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.
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.
Hi Dave. Do you have a copy of xdebug.so that is compatible with PHP 5.6 & Zend Server 8.5?
Spot on – Thanks David
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
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.
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.
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
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.
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
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
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
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
It was also suggested to try and call the breakpoint by calling this function in your PHP:
xdebug_break()
https://xdebug.org/docs/all_functions