Debugging PHP with Netbeans and XAMPP

Note that this is optional. Our projects are simple enough to be debugged by echo and error_log additions to code. Note that echo alone is not sufficient, because sometimes the error prevents the page from displaying at all, so the echo output is lost.

First you need to edit your php.ini. This is explained in the appendixes of M&H, but they assume that there lines about xdebug already in the file, but more recent XAMPP installations have nothing about xdebug.  The lines you need to add for Windows are (as explained in this article)

xdebug.remote_autostart = 1

After this edit, restart Apache.

The same article goes on to cover the Mac case, but I haven't tried it. Let me know if you can make it work. The needed DLL will be something like on Mac or Linux.

Using the Debugger

Start the debugger by clicking the project and selecting Debug, or using an icon at the top.

You may think that nothing is happening at the start, because nothing shows in the browser window and that is often on top on your screen. You need to select the Netbeans window and use the down arrow icon to move the cursor through the PHP code, or use the continue button. You won't see anything in the browser window until the PHP code sends the response HTML out from the server. See this video.

When the page does display, it's being handed over to you as the user. You need to do something with the browser window to get the server code running again (click a link or button or ...).  When the server code does run, it will stop in the debugger again at the start of the page's code.  So you need to go back to the Netbeans window and handle its execution there.