Laravel, Valet, and XDebug

I’ve been exploring Laravel. Valet made it easy to get up and running quickly on my MacBook and I wrote a simple RESTful api (reminder).

Then I wanted to debug one of the endpoints…

Cool, that’s a job for XDebug. XDebug is an important part of my php toolset but I don’t leave it installed all the time because it can really slow down other php based tools that I use, like Composer. I have a couple of functions in my .zshrc that let me enable and disable XDebug as needed:

<br />
xdon() {<br />
 sed -i '' 's/;zend_extension/zend_extension/' /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini<br />
 grep zend_extension /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini<br />
 export XDEBUG_CONFIG=&quot;idekey=PHPSTORM remote_host= remote_port=9001&quot;<br />
<p>xdoff() {<br />
 sed -i '' 's/^zend_extension/;zend_extension/' /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini<br />
 grep zend_extension /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini<br />
 unset XDEBUG_CONFIG<br />
}<br />

I’m not going to go in depth about what these functions do (that’s another blog post). But I expected to be able to set a breakpoint in PhpStorm and then, in a shell, type:

curl ''

Nope, didn’t work. So I did the dance of checking all the things:

  • PhpStorm listening for debug? check
  • Using port 9001? check
  • PhpStorm directory mappings? check
  • search the web… this

Long story short: Valet sets your Mac up to be an nginx webserver delegating web requests to php-fpm. But php-fpm read my php.ini config files long before shell command edited them to enable XDebug. Quick solution:

valet restart

And I’m a happy man 🙂

Comments are closed.