To get XDebug working with Laravel Valet & NetBeans, I needed to do the following:
- Install XDebug via Homebrew:
brew install homebrew/php/php70-xdebug
- Enter NetBeans’s Preferences > PHP > Debugging:
- Change the port from
9000
to9001
.
(This is because Valet runs on 9000 by default.) - Uncheck “Stop at first line”.
(This is because Valet is listening to all requests, andserver.php
will get hit a bunch of times in the same page refresh.)
- Change the port from
- Edit
/usr/local/etc/php/7.0/php.ini
- 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.
- Restart Valet with
valet restart
in your favorite terminal app.
Note thatbrew 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.