Setting up XDebug with PHPStorm and Valet Development Environment

Table of contents


  1. Homebrew should be installed
  2. Valet should be installed and running:
  3. Browser extension for PHPSTORM should be installed:
gerry@webgarten ~ % brew install pecl
gerry@webgarten ~ % pecl install xdebug

In case of error message:
Warning: mkdir(): File exists in System.php on line 294
PHP Warning: mkdir(): File exists in /usr/local/Cellar/php/7.4.7/share/php/pear/System.php on line 294
Warning: mkdir(): File exists in /usr/local/Cellar/php/7.4.7/share/php/pear/System.php on line 294
ERROR: failed to mkdir /usr/local/Cellar/php/7.4.7/pecl/20190902
gerry@webgarten ~ % mkdir -p /usr/local/lib/php/pecl
gerry@webgarten ~ % pecl install xdebug
Installing '/usr/local/Cellar/php/7.4.7/pecl/20190902/'
install ok: channel://
Extension xdebug enabled in php.ini

gerry@webgarten ~ % valet restart
gerry@webgarten ~ % php -m | grep xdebug

[nothing found]

Remedy: Add to PHP.ini, first find PHP.ini:

gerry@webgarten ~ % 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
Additional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
gerry@webgarten ~ % subl /usr/local/etc/php/7.4/php.ini

We use Sublime, any other text editor will do. Insert in PHP.ini:

Execution time can be adjusted in php.ini to prevent early timeouts (504) from Nginx during debugging:
max_execution_time = [number_in_seconds] e.g. 1800

Save php.ini and go:
gerry@webgarten ~ % valet restart

Happy debugging!