Setting Up XDebug

See Also 

NetBeans IDE supports the XDebug third-party PHP debugger. If Xdebug is installed correctly and the PHP environment is configured correctly, you can debug PHP projects inside the IDE. You can also debug PHP files remotely if you set up path mapping.

Additional information can be found in the following wiki document.

.

Checking If XDebug Is Installed

The first step you should take is to see if XDebug is already installed on your system. Some AMP packages come with XDebug. Run phpinfo(). If there is an XDebug section in your PHP info, XDebug is installed. If XDebug is installed, go to Setting Up XDebug

Installing XDebug

The NetBeans IDE for PHP community consensus is that the XDebug installation wizard should be used to install XDebug.

  1. Run phpinfo().
  2. Copy the results of phpinfo() from your browser into the clipboard.
  3. In a browser window, open the following URL.
    .
  4. Paste your PHP info into the XDebug wizard form and click Analyze.
  5. Follow the instructions that appear.

Setting Up XDebug

In this section we assume you have XDebug installed and you need to set it up.

  1. Run phpinfo().
  2. In the PHP info, find the entries for Loaded Configuration File and Additional .ini Files Parsed.
  3. For each php.ini or xdebug.ini file you find, open that file and perform the following steps:
    1. Make sure the file contains the following settings:
      zend_extension=[path to xdebug .so or .dll]
      xdebug.remote_enable=1
      xdebug.remote_handler=dbgp
      xdebug.remote_mode=req
      xdebug.remote_host=127.0.0.1
      xdebug.remote_port=9000
      • These settings are usually in a section labeled [XDebug]. If such a section does not exist, create one. However, some AMPs may differ. For example, in some versions of XAMPP AMP, the line zend_extension = "G:\xampp\php\ext\php_xdebug.dll" is outside of the [XDebug] section, and the name of the .dll file is nonstandard (php_xdebug.dll instead of xdebug.dll).
    2. Comment out all entries for Zend Optimizer, Zend Studio Debugger, or other Zend extensions.

Testing XDebug

Before trying out XDebug from inside NetBeans IDE, you should test your XDebug installation from the command-line. One way to test XDebug is to write a test in PHP and run a debug session on it.

  1. You need an arbitrary PHP file. If you do not have one, create a file called index.php, put any code into it and save it.
  2. Using a text editor, create a file called dbgtest.php and type or paste the following code into the file (save the file afterward).
    <?php
      $address = '127.0.0.1';
      $port = '9000';
      $sock = socket_create(AF_INET, SOCK_STREAM, 0);
      socket_bind($sock, $address, $port) or die();
      socket_listen($sock);
      $client = socket_accept($sock);
      echo "Connection established: $client";
      socket_close($client);
      socket_close($sock);
    ?>
  3. Run the code from the command line (e.g. /usr/bin/php dbgtest.php, see ).
  4. Start a debug session for an arbitrary PHP file from within a browser window (e.g. http://localhost/index.php?XDEBUG_SESSION_START=mysession).

If XDebug is properly configured, the script started in step 3 should print a message like "Connection established: Resource id #5". If no message is printed and the script is still running, xdebug is not properly configured or uses a different port or has another problem. In this case, kill the running process and investigate where the problem is.

Setting Up Debugging Options in NetBeans IDE

After you install, configure, and successfully test XDebug, you can set up XDebug options in the IDE. To learn more about these options, open Tools > Options (NetBeans Preferences on Mac), go to the PHP Options, open the Debugging tab, and click Help.

For more information about XDebug, see the following documents.

(NetBeans wiki page)

(NetBeans PHP User's Forum thread)
See Also

Legal Notices