CakePHP debug in NetBeans

Bookmark and Share

Debugging code can be the most vital task a developer required to do. Debugging makes it easy to find logical errors in code. NetBeans supports PHP debug using xdebug, but in CakePHP it is hard to make this work straight. This is due to custom, pretty, URL rewriting. However you can enable debugging even with pretty URLs and URL rewriting.

To make this works in simple few steps first make sure that xdebug is installed and working. To make sure it is installed open you php info file or create a new php file and fill it with:

<?php echo phpinfo(); ?>

and open it in your browser and make sure that xdebug appears like this:

XDebug Section in phpinfo()

XDebug Section in phpinfo()

If you found xdebug is not installed then you can find many resources on how to install xdebug on Google. If it is already installed then make sure that your xdebug is configured correctly in your php.ini. NetBeans requires xdebug to be configured as follows:

xdebug.remote_host= #or your preferred hostname

Now we will start enabling CakePHP debugging:

  • First you’ll need to create a new CakePHP application using CakePHP console or use current CakePHP application folder.
  • In NetBeans create a new PHP application and select “PHP Application with Existing Sources” and click next.
  • Select your application folder and choose a name for you application and click next.
  • Write your project base URL and make sure to select index.php as your ‘Index File’ and click finish.
  • Go to Projects panel and right click your project and select Properties from the menu on left select Sources then select your Web Root folder, and it is ovious what to select :)
  • Run Configuration and click Advanced. From the dialog select “Ask Every time” and click OK to close the dialog and click OK again to close Project properties dialog.

Now the configurations are complete and you can set break points. To create a break point you can click on the line number on the left of source code or write xdebug_break(); where you want to stop program execution.

Break point in NetBeans

Break point in NetBeans

When you click debug icon in NetBeans toolbar, or select Debug project from Debug menu (ctrl + F5), NetBeans will show you a box where you enter the URL you want to debug and it will stop execution of the application, and your browser will not continue loading your page until you click Continue.

NetBeans PHP debug pane

NetBeans PHP debug pane

Now you can debug all your CakePHP source code as normal PHP applications. You can learn how to debug normal PHP application in NetBeans from this article

14 comments on “CakePHP debug in NetBeans

  1. Pingback: Tweets that mention CakePHP debug in NetBeans | TipLite --

  2. hi, I am a beginer using cakephp and netbean, all above setting is ok for xdebug, but I set a breakpoint at my users_controller/login action and it should relate to the url:/localhost/users/login , not index.php in my wwwroot, I can’t let it stop at breakpoint, do you know some tips that can help?

    Best Regards
    LX 😎

  3. Did you follow steps in the article? it explains what is required for them to run together. Also make sure you have configured xdebug right.

  4. Yes, I did it and I can debug any PHP code in any site. Try any CakePHP project, run NetBeans in debug mode, put the break point in any controller, view or model. The debug will not stop in any of them. Your post has nothing to do real CakePHP project. Let me know if you find some thing?


    • Are you sure you set your source folder to webroot? Right click your project and choose properties, then set your source folder to webroot.

      • Thanks so much …. I spent many hours trying to get the debugger working, but I couldn’t. Once I have read this hint it worked like a charm ….. :)

        • Please go again to run configuration of your project and select advanced. You will find server directory map point ‘/’ to your ‘webroot’ folder or create a virtual host on your apache system and use. i prefer the virtual host solution as it is more cleaner.

  5. hey, i followed your instructions, and i got netbeans to stop at breakpoints but i am not able to see any variables. Are you able to inspect variables on breakpoints?

  6. Pingback: CakePHP debug in NetBeans | Northwind Traders Documentation

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>