Making Xdebug, Laravel Valet, PHPStorm, and Composer play nice
There are a handful of resources out there that explain how to set up Xdebug in PHPStorm, and maybe a couple on how to set it up in Valet. That’s great and all, but I’m sure you’ve also seen this:
ou are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
How annoying. But if you disable Xdebug, you can’t use it, obviously. Here’s how you can have the best of both worlds.
Disable Xdebug for the CLI
PHPStorm seems to still need Xdebug enabled when runs in Apache. Version 2016.2 says you can load it on demand, but I couldn’t figure that out. Meh, onwards.
If you’re using a relatively stock configuration, your php will be loading /usr/local/etc/php/7.0/php.ini.
Create a CLI version of php.ini
PHP will load the appropriate ini file suffixed with the SAPI, if it exists. Great, just make a copy of it to reference cli.
cp /usr/local/etc/php/7.0/php.ini /usr/local/etc/php/7.0/php-cli.ini
Ensure it only loads Xdebug from Apache
In addition to loading php.ini, it also loads all ini files in /usr/local/etc/php/7.0/conf.d/. There’s an ext-xdebug.ini in there which is responsible for loading Xdebug. Since we only Xdebug in Apache, copy the contents of that and paste it at the bottom of your /usr/local/etc/php/7.0/php.ini file (that’s the one Apache will use).
It should look something like this:
[xdebug] zend_extension="/usr/local/opt/php70-xdebug/xdebug.so"
Then delete ext-xdebug.ini, or rename it to ext-xdebug.ini.bak if you’re a paranoid hoarder.
Enable Xdebug for Valet
Back in php.ini, add these right where you left off above:
xdebug.remote_enable=1 xdebug.remote_autostart=1 xdebug.remote_port=9001
By default the Xdebug port is 9000, but that’s what Valet runs on, so you’ll need something different.
How does 9001 sound? Perfect.
Restart PHP
At this point you’re done messing with PHP settings. To make them take effect, its simple:
valet restart
Confirm it worked
Originally published at www.laravelfeed.com.