Using Xdebug with Laravel Valet

Published:
Author: Ally

First, assuming you have installed valet:

pecl install xdebug

Next, find which files are loaded by the PHP installation:

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

Create a new file 99-xdebug.ini in the Scan for additional.ini files in folder, i.e. /usr/local/etc/php/7.4/conf.d:

xdebug.mode = "develop,debug"
xdebug.client_host = "localhost"
xdebug.client_port = "9003"
xdebug.idekey = "phpstorm"
xdebug.start_with_request = "yes"

Then restart valet, valet restart.


I’ve added this to my .zshrc and effortless changes without having to remember the path and to reset valet for the config changes to be reloaded.

function xdebug
{
    nano /usr/local/etc/php/7.4/conf.d/99-xdebug.ini; valet restart
}

Configuring PHPStorm

Go to preferences -> PHP.

I like to uncheck the two Force break.. checkboxes and set the Debug port to 9003 only (since I have port 9000 in use already for Graylog).

PHPStorm: PHP preferences

Go to Run -> Edit configurations.

PHPStorm: Empty configurations

Attach new remote PHP.

PHPStorm: Add configuration

Give a suitable name and IDE key.

PHPStorm: Added configuration

Creating a fresh Laravel installation with Docker
Some handy local development environment tools/services
To bottom
To top
< SM
max-width: 640px