Jul 082017
 

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: 192.168.0.3
    • IDE: Netbeans 8.2
  • guest:
    • OS: Debian Jessie 64 bits in VirtualBox
    • IP: 192.168.0.4 (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:
  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, 192.168.0.3 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

Apr 152011
 

Bon, en fait, je ne sais pas si je suis le premier à coder ainsi. Mais comme j’aime vraiment le modèle que j’ai conçu pour organiser les scripts de Fuu-Doh! v2, je pense que je partagerai bientôt le concept aux développeurs PHP qui pourraient en être intéressés.

C’est un modèle de conception qui est très simple à comprendre et très structuré, avec beaucoup d’imbrications d’objets. Je suis actuellement sur du PHP 5.2, je ne peux pas garantir pour l’instant que le modèle sera compatible aux versions précédentes de PHP qui gèrent les classes. Mais je pense qu’il n’y a pas vraiment de problème sur ce point.

J’espère me trouver un peu de temps libre pour pouvoir vous l’expliquer. 🙂