Using Netbeans with XDebug

Tom J Nowell edited this page Feb 4, 2018 · 20 revisions

VVV 2

Note: These are old instructions for VVV 1, and will not work in VVV 2+. For the latest documentation see here


This tutorial is an extension and it's based on this tutorial here. Feel free to modify and add any relevant information :)

For this tutorial I've used:

  • Ubuntu 13.10 X86_64
  • Virtual Box 4.3.12
  • Vagrant 1.6.3
  • VVV 1.2
  • Netbeans 8.0

Setting up Vagrant

  1. Open terminal and inside your Vagrant directory, start vagrant using vagrant up
  2. Inside your Vagrant directory, ssh into the Vagrant machine vagrant ssh
  3. Inside the Vagrant machine, turn on XDebug xdebug_on

Configuring Netbeans Project

  1. Inside the "New Project" dialogue, choose "PHP Application with Existing Source" PHP Application with Existing Source

  2. Inside the "New PHP Project with Existing Sources" dialogue:

    • Sources Folder: {VVV folder}/www/wordpress-develop
    • PHP Version: 5.5 PHP Project with Existing Source dialogue
  3. Inside the "Run Configuration" dialogue:

  4. Click on Finish

  5. Inside the Projects Tab, right click your project and click on Properties

  6. Select "Run Configuration" and click on Advanced Run Configuration - Advanced

  7. Inside the "Advanced Web Configuration":

    • Debug URL: Do Not Open Web Browser
    • Path Mapping: * Server Path: /srv/www/wordpress-develop * Project Path: {VVV folder}/www/wordpress-develop Advanced Web Configuration
  8. Click on OK

  9. Inside Tools > Options > PHP > Debugging Tab:

    • Session ID: VVVDEBUG
    • Stop at First Line: unchecked PHP Debugging Tab
  10. Click on OK

Example 1: Testing XDebug in a Wordpress Theme

  1. Inside your wp-content/themes/twentyfifteen (if your current theme is twentyfifteen) folder, select the index.php file
  2. Select the get_header() line in the beginning of this file and add a breakpoint on it
  3. Press F11 to start debugging the project Debugging Editor - Web Waiting
  4. In your browser, access http://src.wordpress-develop.test/. Your editor screen should look like this: Debugging Editor - Web Running

Example 2: Testing XDebug in PHPUnit test

Note: In order to Debug phpunit tests, you have to modify the file /tests/phpunit/includes/bootstrap.php (Thank you, KajMagnus )

Change the line:

system(WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );

to

 system('XDEBUG_CONFIG="remote_enable=Off" ' . WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );
  1. Open the following test file in the editor: tests/phpunit/includes/bootstrap.php
  2. Add a breakpoint in the following line: require_once $config_file_path;
  3. In the terminal, inside your Vagrant directory, ssh into the Vagrant machine vagrant ssh
  4. Change your current directory to the wordpress version you are working on cd /srv/www/wordpress-develop/
  5. Press F11 to start debugging the project
  6. In the terminal, run phpunit tests/phpunit/tests/theme
  7. Your editor screen should look like this: Debugging Editor - PHPUnit

Gotchas:

  1. If you follow the above and have trouble getting it to work, verify the Vagrant machine is using the right IP address to communicate with the host machine. Specifically, in the Vagrant machine, in /etc/php5/fpm/conf.d/20-xdebug.ini check that the setting xdebug.remote_host points to the host machine's IP address, usually "10.0.2.2". When you first ssh into the Vagrant machine it says where you are accessing from, or you can use netstat -r
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.