Xdebug debug with Netbeans on Linux

XDebug is a free PHP extension to debug variables of your applications. Combined with Netbeans for PHP debug features (break points, variable watching and flow execution navigation, see screenshot on the left), it allows to have a complete debug environment.

What it’s really interesting is the possibility to place breakpoints in any file, even though not called directly in the local URL. That is required when working with web applications with URL routing/rewriting sudh as MVC applications (Zend Framework, Symfony etc..)  where the PHP code in a controller action does not match with its path in the local URL.

Here are the easy steps to follow in order to configure Xdebug for Linux Ubuntu 10.04 LTS. I’ll write the full commands to make it easier by copy & paste.

-) download the xdebug extension

sudo apt-get install php5-xdebug

-) check where the extension is installed

sudo find /usr/lib/php5 | grep xdebug

-) open the php.ini file (inside apache)

sudo vim /etc/php5/apache2/php.ini

and add these lines at the end of the file (replace with the right module path)


note1: xdebug.so could be elsewhere. use find /usr/lib -name xdebug.so to find the correct path
note2: see other xdebug settings

-) restart apache

sudo /etc/init.d/apache2 restart

-) Netbeans: tools->options->PHP
Tick ”Watches and Baloon Evaluation” (*), Untick “Stop at first Line” (not really useful except when debugging the application bootstrap).

(*): Xdebug is unstable with this options, however I found it very useful and enough stable for my purposes. It’s possible that Netbeans crashes with the current version, restart it in case.

5) Netbeans: right click on the project ->properties->Run configuration -> run as local website. Insert the (virtualhost) local URL. Do not insert any index file if the application uses URL routing, or Netbeans will launch the relative script path in the URL.

6) Netbeans: place your breakpoints by clicking on the line number, then start the debug (Under Debug->debug or Ctrl+F5). Netbeans will open the browser at the local URL, and when reaching the breakpoitns, netbeans will show a red icon on the line.
Depending on the browser, the focus will return to Netbeans (go manually if it does not).
Select the code / expression to watch/evaluate. Netbeans will show a baloon tip with the value. Alternatively, right click and select “new watch” to have the expression and the values appearing in the debug panel.
Use F5 to go to the next breakpoint, F7/F8 to step into/over.

As mentioned, Xdebug is unstable with the option set in the step 4. If watching some expressions crashes netbeans, use the “new watch” option instead.

5 thoughts on “Xdebug debug with Netbeans on Linux

  1. Xdebug debug with Netbeans on Linux

    Very useful step by step instruction. Thank you very much Elvis.

    Best regards from Ole (Denmark)

  2. Hi Elvis,

    a good post on a good topic; however if you’re configuring on Ubuntu Linux, what about configuring via the xdebug.ini file in /etc/php5/apache2/conf.d for a cleaner configuration setup?

    I feel that the PHP community should encourage proper debugging a lot more, instead of the usual print/echo/die etc. What do you think? Which do you find more useful and productive?



  3. Thanks for the conf.d suggestion. I need to check if it’s supported on the Windows version of apache.

    Debugging it’s really useful. I must say though that xdebug is not 100% stable and sometimes a customized function to debug (at least with backtrace, and automatically deactivate on production env) it’s better.
    Debugger included in Zend Studio is much better, but not free 🙁

    Also sometimes it’s not possible to efficiently debug with only breakpoints (let’s say then the foreach is considering a certan key) and custom debug code is necessary.

    In general, I think it’s necessary to think carefully when developing algorithm to reduce the time spent to debug problems. Also a TDD approach would help to understand exactly which tests fail and that would help to locate the problem sooner.

    thanks for your comment !

Comments are closed.