Configuring and connecting NetBeans with XDebug to run and debug local PHP projects and scripts is very simple.
These instructions will work for any WAMP, such as Xampp or WampServer, but are specific to WampDeveloper Pro (as it already provides everything needed).
Load and Configure PHP’s XDebug Extension
Open PHP’s configuration file: php.ini.
Find and un-comment the XDebug section that already exists near the end of php.ini, by removing the “;” from each settings line. Save file. Restart Apache.
[XDebug] ; Note that profiler is enabled separately. zend_extension="C:\WampDeveloper\Components\Php\ext\php_xdebug.dll" xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000 xdebug.remote_autostart=0 xdebug.remote_connect_back=0 xdebug.profiler_enable=0 xdebug.profiler_enable_trigger=0 xdebug.profiler_output_name=cachegrind.out.%s.%t xdebug.profiler_output_dir="C:/WampDeveloper/Temp/xdebug" xdebug.trace_output_dir="C:/WampDeveloper/Temp/xdebug"
The provided XDebug settings will work with the NetBeans IDE out-of-the-box. The configuration uses as many default values as it can, and nothing needs to be changed as long as NetBeans is on the same system WAMP is on.
Create NetBeans Project
We will set up a project that uses the www.example.com website, and it’s contents (the index.php file).
PHP Application with Existing Sources
* Changed from the pre-filled default to update to the website’s DocumentRoot folder.
Local Web Site (running on local web server)
* Changed from the pre-filled default of “localhost” to website’s
Primary Domain Name. And removed the “/webroot” part, as it’s not a URL, it’s the website’s
In NetBeans, open the index.php file, and set a debug break-point on any PHP line.
* Use “<?php” instead of “<?” for your PHP code unless you’ve enabled the NetBeans option to use short-tags in the project.
Make sure Apache is running, and click the IDE’s “Debug Project” (not “Run Project”) icon.
It will open the system’s default Browser to URL:
That “XDEBUG_SESSION_START” part tells PHP to start XDEBUG for that request, and it will provide NetBeans the debug data by sending it to the specified IP and Port (in php.ini) / which is the address NetBean’s XDebug client is listening on.
You should be able to now step through the PHP code using the NetBeans IDE!
If for some reason your PHP code can’t handle the query string, you can enable “
xdebug.remote_autostart=1” (php.ini) to auto start debugging for all requests. But this will slow everything down further, and also generate much more data.
Once done, make sure to stop the Debugging process so everything get’s cleared out.
If there are any issues with Apache and PHP request timeouts, these can always be increased.
And if any odd issues start happening with either the Browser or the XDebug sessions:
- Make sure to stop NetBeans Debugging.
- Go into the Browser’s settings, and clear out the entire History, Temp files, and Cache, then close it.
- Restart Apache.
Also, it’s best to not use IE as the default Browser for NetBeans, but to change to using the “Embedded WebKit Browser”, via the Project’s properties.