Configure XDebug on WAMP and Netbeans

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.

  1. Before starting, make a note of the PHP version enabled, its Compiler and Architecture values from phpinfo().
  2. Go to https://xdebug.org/download.php and download the relevant .dll file based on the information collected in step 1.
  3. 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
  4. 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
  5. 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"
  6. Change the below parameters to the given values.
    output_buffering = Off
    
    implicit_flush = On
  7. Save the php.ini file and restart the Apache service
  8. Verify that xdebug is enabled in your WAMP’s phpinfo page. Go to http://localhost/?phpinfo=1 and look for the section – xdebug.
  9. Configure your IDE to use xdebug

Configuring Netbeans

  1. Go to Tools menu > Options > PHP > Debugging and give the following options.
    1. Debugger port: 9000
    2. Session ID: netbeans-xdebug
    3. Maximum Data Length: 2048
    4. Stop at first line: checked
    5. Show debugger console: checked
  2. Click on OK to save the configuration
  3. Open your desired PHP file and place a breakpoint beside the line number of your choice
  4. Go to Debug menu and click on Debug Project or Debug File
  5. Netbeans will start listening to XDebug on the given 9000 port.

In this way, you can debug your PHP script using XDebug.