Setup Xdebug with PHP7.2, PHPStorm and Laravel Valet

This walkthru assumes that you have Laravel Valet, PHP7.2 installed. If not, follow these instructions: https://laravel.com/docs/5.8/valet#installation

Xdebug is no longer available from Homebrew as shown in tutorials for PHP7.1, we are going to use PECL instead.

Install Xdebug

Let’s see what we got so far:

Your output should look something like this:

Configuration File (php.ini) Path: /usr/local/etc/php/7.2
Loaded Configuration File:         /usr/local/etc/php/7.2/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.2/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.2/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.2/conf.d/php-memory-limits.ini

If you don’t see a ext-xdebug.ini which sometimes can be gone missing, just create one: touch /usr/local/etc/php/7.2/conf.d/ext-xdebug.ini

[xdebug]
zend_extension="/usr/local/opt/[email protected]/pecl/20170718/xdebug.so"
xdebug.remote_autostart=1
xdebug.default_enable=1
xdebug.remote_port=9001
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM

The default port is 9000, but I am going to use 9001 since I have a Elastic Search server running on port 9000.

PHPStorm

Next we are going to configure PHPStorm to listen for Xdebug.

Open PHPStorm settings (cmd-,)

Languages & Frameworks > PHP > Debug > DBGp Proxy

Add PHPSTORM as IDE Key and port 9001

Next, open Languages & Frameworks > PHP > Debug

Working

Make sure Xdebug is listening to port 9001 and ”Can accept external connections” is checked.

Working

Uncheck to two first ”Force break…”-options, otherwise you will always start debugging on Laravel Valet’s server.php-file

Click ”Start listening for debug connections”

Working

Add a breakpoint and reload your page and it should hopefullt work :-)

Working

Done!

Troubleshooting

Stops working after an update

If you get similar errors:

Cannot load Xdebug - it was already loaded

Check if your php.ini-file contains zend_extension="xdebug.so" remove this line. The PECL-installer can somethimes add this during upgrades.