Xdebug is an extension for PHP to assist with debugging and development. It contains a single step debugger to use with IDEs; it upgrades PHP’s var_dump() function; it adds stack traces for Notices, Warnings, Errors and Exceptions; it features functionality for recording every function call and variable assignment to disk; it contains a profiler; and it provides code coverage functionality for use with PHPUnit. This article contains a step by step instruction guide in configuring XDebug on your WAMP Server (http://www.wampserver.com/en/) on Windows.
- Before starting, make a note of the PHP version enabled, its Compiler and Architecture values from phpinfo().
- Go to https://xdebug.org/download.php and download the relevant .dll file based on the information collected in step 1.
- Place the downloaded dll file in your WAMP’s PHP folder. e.g. C:\wamp64\bin\php\php7.1.9\zend_ext\php_xdebug-2.5.5-7.1-vc14-x86_64.dll
- Open php.ini from the WampServer’s manager in the system tray, i.e. [W] > PHP > php.ini. Alternatively, you can find the php.ini in use in the WAMP folder also. e.g. C:\wamp64\bin\apache\apache2.4.27\bin\php.ini
- Add the code below to the bottom of your php.ini. (replace the path with the relevant one)
[xdebug] zend_extension ="c:/wamp64/bin/php/php7.1.9/zend_ext/php_xdebug-2.5.5-7.1-vc14-x86_64.dll" xdebug.extended_info=on xdebug.profiler_enable = on xdebug.profiler_enable_trigger = on xdebug.profiler_output_name = cachegrind.out.%t.%p xdebug.profiler_output_dir ="c:/wamp64/tmp" xdebug.show_local_vars=0
xdebug.remote_enable=on xdebug.remote_handler=dbgp xdebug.remote_host=localhost xdebug.remote_port=9000 xdebug.remote_autostart=on xdebug.idekey="netbeans-xdebug"
- Change the below parameters to the given values.
output_buffering = Off implicit_flush = On
- Save the php.ini file and restart the Apache service
- Verify that xdebug is enabled in your WAMP’s phpinfo page. Go to http://localhost/?phpinfo=1 and look for the section – xdebug.
- Configure your IDE to use xdebug
Configuring Netbeans
- Go to Tools menu > Options > PHP > Debugging and give the following options.
- Debugger port: 9000
- Session ID: netbeans-xdebug
- Maximum Data Length: 2048
- Stop at first line: checked
- Show debugger console: checked
- Click on OK to save the configuration
- Open your desired PHP file and place a breakpoint beside the line number of your choice
- Go to Debug menu and click on Debug Project or Debug File
- Netbeans will start listening to XDebug on the given 9000 port.
In this way, you can debug your PHP script using XDebug.