Screen Shot 2016-05-10 at 11.09.35.png

To get XDebug working with Laravel Valet & NetBeans, I needed to do the following:

  1. Install XDebug via Homebrew:
    brew install homebrew/php/php70-xdebug
  2. Enter NetBeans’s Preferences > PHP > Debugging:
    1. Change the port from 9000 to 9001.
      (This is because Valet runs on 9000 by default.)
    2. Uncheck “Stop at first line”.
      (This is because Valet is listening to all requests, and server.php will get hit a bunch of times in the same page refresh.)
  3. Edit /usr/local/etc/php/7.0/php.ini
  4. Add this bit to the end:
    [xdebug]
    xdebug.remote_enable=on
    xdebug.idekey="netbeans-xdebug"
    xdebug.remote_port=9001

    This turns on remote debugging, and tells XDebug to look for NetBeans’s IDE key.

  5. Restart Valet with valet restart in your favorite terminal app.
    Note that brew services restart php70 isn’t enough here; you need to restart Valet entirely.

Also…

Live debugging using XDebug will severely degrade Valet’s otherwise snappy performance. Composer will even tell you this:

You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug

This is normal. XDebug is a hugely powerful realtime interpreter, debugger, and profiler, and it’s going to slow things down while it’s listening to all that PHP chug along. (You may be able to tune this a bit using all of XDebug’s extensive settings.)

If you’re worried about battery life, most IDE’s (like NetBeans) will let you turn debug sessions on and off. So debug, do your thing, find the bug, kill the bug, and turn it off.


About the Author

I help build WordPress, BuddyPress, bbPress, BackPress, and a bunch of other pretty neat stuff.