zen of coding

Setup debugging for Netbeans + CakePHP

Update (7/22/2011): dogmatic69 pointed out that you can do the same with Chrome by installing the xdebug extension. See his comment for details.

For all the Netbeans users out there, if you don’t have debugging enabled, this little “how-to” should get you stared pretty easily.

First prerequisite is to make sure you have xdebug installed and enabled for PHP.

In the php.ini you should have the following settings:

xdebug.remote_host="localhost" #or try

Make sure that the xdebug extension is enabled, of course.
(Under the [XDebug] section of php.ini, zend_extension=[path to your php_xdebug lib]).
Don’t forget to restart your web server ;)

Next we’ll install the Netbeans Fire Fox add-on.
It can be downloaded from here: https://addons.mozilla.org/en-US/firefox/addon/easy-xdebug/
As you can guess this means that FF should be your default browser, because it will need to open up once you start running the debugger.

Let’s switch to Netbeans, right click on the app of interest and navigate to “Properties”.
In the project properties window select “Run configuration”.
Project URL: http://yourhost.example.local/ (the local host name from which your app is running).
Index File: index.php (easy enough).

Double check some options in Netbeans…
Tools -> Options -> PHP tab
“PHP Interpreter” should point to the correct location of your PHP executable.
“Debugger Port” should be the same as the setting in your php.ini (xdebug.remote_port=9000)
You might want to “uncheck” the “Stop at First Line” box.

This should be it, as far as the setup goes…

You can now run a quick test:
Open app/webroot/index.php.
Add a breakpoint at some line.
(You might want to add xdebug_break(); at the bottom of the file, just to be sure).
Hit Ctrl+F5 (or whatever is the command on your OS to debug the project).

If all goes well FF should open up and you should see the code execution stop at the line where you’ve set the breakpont with some debug info in the Netbeans console.

p.s. Setting up other IDE’s should be similar in the overall approach… but, as always, your mileage may vary.

  • Thanks for the info. I had issues where xdebug_break(); was working fine but setting a breakpoint in netbeans was not working. This was fixed by going to the project properties (right click project, then properties) and setting the web root folder to APP/webroot.

    There is also a chrome extension, so there is no need to head back to the bloated world of ff https://chrome.google.com/webstore/detail/eadndfjplgieldjbigjakmdgkmoaaaoc

    • Bambam

      @dogmatic69: I was having the same problem with breakpoints and was due to the root folder. Good contribution to this article!

    • otulga

      Wow! You saved my life! Thank you it was exactly due to project web root

  • teknoid


    Awesome, thanks for sharing the link.

  • Harris

    What if you put a breakpoint at PostController for example in function index()?

    If you point at /posts/ will it stop in the breakpoint?

  • teknoid


    Sure, that’s the whole point :)
    Or you can navigate your browser while stepping through the code.

  • oboeguy53

    YOU ARE THE MAN!! I’ve been trying to solve this for three days and this is the first answer that has worked. Thanks for sharing!!

    You ROCK!!!

  • Help please.

    New to cakephp and having difficulty in setting up Netbeasns 7.11 to run and debug a cakephp 2.1.0 project.

    Able to run and debug non-caskephp projects and files in 7.11.

    The values in Netbeans project properties for the cakephp project are:
    Project Folder – f:\xampp\htdocs\cake_blog_example
    Source Folder – f:\xampp\htdocs\cake_blog_example
    Run configuration
    Run as – Local Web site(running on local server)
    Project URL – http://localhost/cake_blog_example/
    PHP Include Path
    Index File – as below with corresponding error message

    app/webroot/index.php – Missing Method in AppController

    app/index.php – Missing Method in AppController

    index.php – Missing Controller

    What is incorrect or missing?

    Many thanks.

    (the tvldwa-online site needs to be re-engineered – hence iterest in cakephp)

%d bloggers like this: