[Drupal] VM + XDebug + Netbeans

Hey! Long time no see! Heehee.

I am just dropping a note here about the basic steps of how to install XDebug for a specific setup.

Here is my configuration:

  • host:
    • OS: Windows 7 64 bits
    • IP:
    • IDE: Netbeans 8.2
  • guest:
    • OS: Debian Jessie 64 bits in VirtualBox
    • IP: (bridged network in VirtualBox settings)
    • standard Apache2, PHP 5, MySQL from official repositories

The idea is: I want to use the stepper on a website located inside a virtual machine from an IDE on the host machine.

Step by step

XDebug installation

  1. On the guest machine, get the phpinfo() output. If you have no idea how to do this quickly:
    1. From the command line, run php --info > ~/tempphpinfo.txt (you can safely delete this file later).
    2. Open the file: gedit ~/tempphpinfo.txt.
    3. Copy all the contents.
  2. Go to https://xdebug.org/wizard.php and follow the instructions: you will have to paste the contents of the phpinfo obtained earlier. The wizard will tell you exactly how to build xdebug. Make sure you are in the correct folder when running the phpize command.
  3. Locate the xdebug.ini files (named 20-xdebug.ini on my Debian) on the guest machine:
    1. cd /etc/php5
    2. find | grep xdebug
  4. Edit one of the files listed by the last command and add those lines:
    ;zend_extension=[path to xdebug .so/.dll]
  5. sudo service apache2 restart, just in case.

Testing XDebug

We will create a small php file which will react to XDebug calls.

  1. Create a php file:
    • touch ~/testxdebug.php
    • gedit ~/testxdebug.php
    • Insert the following:
    • Save and close.
  2. Start the command line debugger: php ~/testxdebug.php. You may have a warning about the xdebug extension already started: you can ignore it or fix this later by commenting/removing the zend_extension=path/to/xdebug.so line you have added to the /etc/php5/cli/php.ini file (not the xdebug.ini files!).
  3. In the web browser, go to your website location, a Drupal 8 in my case and add an attribute at the end of the URL, e.g.: http://localhost/DrupalXDebug/web/index.php?XDEBUG_SESSION_START=mysession.
  4. In the terminal where you have run the php ~/testxdebug.php command, you should see a message like this one:

    connection established: Resource id #5

    If not, the configuration is wrong and check the steps again or the resources links at the end of this article.

Setup remote debugging

Until now, we have only ran the debugger (the little php script we have created earlier, which you can safely delete now) from inside the guest machine. We will configure xdebug to work with remote machines, in my case, the Windows host.

  1. Edit one of the xdebug.ini files you have edited earlier: replace the xdebug.remote_host value by the IP of the host, in my case.
  2. sudo service apache2 restart, just in case.

Netbeans configuration

Now we can configure Netbeans to run the debugger.

  1. Open the website project.
  2. Right click on the project in the Projects list and click on Properties.
  3. Enter the URL of your website in Run Configuration > Project URL. In my case, it was like this:
    Screenshot from netbeans
    Where to set the website URL
  4. Click on the Advanced button.
  5. Set the path mappings. In my case:
    Screenshot of path mapping on Netbeans
    How to set path mappings

You should now be set for debugging with the stepper!

Run the debug

  1. Click on the Debug Project button in the top toolbar of Netbeans and it should launch automatically a browser with a session id already set!
  2. Put a breakpoint somewhere in the code.
  3. Each time a request is sent to the website, Netbeans will control the page generation.

Additional Information

Published by Dakwamine

Dakwamine, alias Quang-Minh Dang, né en 1987 en région parisienne. Un type sympa, pas bavard et pragmatique.