Setup Xdebug in Laravel Valet with PHP 7.3 and PHPStorm

In this tutorial, I will show you how to setup Xdebug in Laravel Valet with PHP 7.3 and use it with the PHPStorm IDE. Prerequisite is a working Laravel Valet setup as described here.

First step is to prepade PECL:

pecl channel-update pecl.php.net ; pecl clear-cache

Now, install Xdebug:

pecl install xdebug

Restart Valet:

valet restart

Now, check if Xdebug is installed:

php -m | grep 'xdebug'

The output should be xdebug.

Now, check for your INI files used by PHP:

php --ini

If the list does not contain ext-xdebug.ini, create this file:

nano /usr/local/etc/php/7.3/conf.d/ext-xdebug.ini

Add this content to ext-xdebug.ini:

[xdebug]
zend_extension="/usr/local/opt/php@7.3/pecl/20180731/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

Next, edit php.ini:

nano /usr/local/etc/php/7.3/php.ini

And uncomment this line:

zend_extension="xdebug.so"

so that is looks like:

; zend_extension="xdebug.so"

Restart Valet again:

valet restart

Configure PHPStorm

Next step is to configure PHPStorm. Open PHPStorm and open the preference panel. Go to Languages & Frameworks > PHP > Debug > DBGp Proxy and set IDE key: to PHPSTORM. Next, set Port: to 9001.

After that, go to Languages & Frameworks > PHP > Debug and set Xdebug port to 9001, check Can accept external connections and clear the two Force break at first line… checkboxes.

Now, you can save the settings and click Start listening for PHP Debug Connections and your debugger should be up and running.

Possible Problems and Solutions

ERROR: `phpize’ failed

If you get an error like this:

downloading xdebug-2.7.2.tgz ...
Starting to download xdebug-2.7.2.tgz (230,987 bytes)
.................................................done: 230,987 bytes
69 source files, building
running: phpize
Configuring for:
PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731
autom4te: need GNU m4 1.4 or later: /usr/bin/m4
ERROR: `phpize' failed

when running pecl install xdebug, the Xcode Command Line Tools may be missing. You can install them by running:

xcode-select --install

After installing the Xcode Command Line Tools, run pecl install xdebug again.

Warning: mkdir(): File exists in System.php on line 294

If you get something like this when running pecl install xdebug:

running: find "/private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2" | xargs ls -dils
8093793   0 drwxr-xr-x  3 sebastian  wheel      96 12 Okt 21:24 /private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2
8094343   0 drwxr-xr-x  3 sebastian  wheel      96 12 Okt 21:24 /private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2/usr
8094344   0 drwxr-xr-x  3 sebastian  wheel      96 12 Okt 21:24 /private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2/usr/local
8094345   0 drwxr-xr-x  3 sebastian  wheel      96 12 Okt 21:24 /private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2/usr/local/Cellar
8094346   0 drwxr-xr-x  3 sebastian  wheel      96 12 Okt 21:24 /private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2/usr/local/Cellar/php
8094347   0 drwxr-xr-x  3 sebastian  wheel      96 12 Okt 21:24 /private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2/usr/local/Cellar/php/7.3.7
8094348   0 drwxr-xr-x  3 sebastian  wheel      96 12 Okt 21:24 /private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2/usr/local/Cellar/php/7.3.7/pecl
8094349   0 drwxr-xr-x  3 sebastian  wheel      96 12 Okt 21:24 /private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2/usr/local/Cellar/php/7.3.7/pecl/20180731
8094350 576 -rwxr-xr-x  1 sebastian  wheel  294172 12 Okt 21:24 /private/tmp/pear/temp/pear-build-sebastianKWT2xy/install-xdebug-2.7.2/usr/local/Cellar/php/7.3.7/pecl/20180731/xdebug.so

Build process completed successfully
Installing '/usr/local/Cellar/php/7.3.7/pecl/20180731/xdebug.so'

Warning: mkdir(): File exists in System.php on line 294
PHP Warning:  mkdir(): File exists in /usr/local/Cellar/php/7.3.7/share/php/pear/System.php on line 294

Warning: mkdir(): File exists in /usr/local/Cellar/php/7.3.7/share/php/pear/System.php on line 294
ERROR: failed to mkdir /usr/local/Cellar/php/7.3.7/pecl/20180731

The pecl symlink in your homebrew php folder may be the source of the problem. To check the php folder run:

cd /usr/local/Cellar/php/7.3.7
ls -la

The output should be something like this:

drwxr-xr-x  15 sebastian  staff    480  8 Jul 21:12 .
drwxr-xr-x   3 sebastian  staff     96  8 Jul 21:12 ..
drwxr-xr-x   4 sebastian  staff    128  3 Jul 13:30 .bottle
drwxr-xr-x   3 sebastian  staff     96  3 Jul 13:30 .brew
-rw-r--r--   1 sebastian  staff   3135  8 Jul 21:12 INSTALL_RECEIPT.json
-rw-r--r--   1 sebastian  staff   3204  3 Jul 13:30 LICENSE
-rw-r--r--   1 sebastian  staff  65943  3 Jul 13:30 NEWS
-rw-r--r--   1 sebastian  staff   1609  3 Jul 13:30 README.md
drwxr-xr-t  12 root       admin    384  8 Jul 21:12 bin
-rw-r--r--   1 sebastian  staff    628  8 Jul 21:12 homebrew.mxcl.php.plist
drwxr-xr-x   3 sebastian  staff     96  3 Jul 13:30 include
drwxr-xr-x   4 sebastian  staff    128  3 Jul 13:30 lib
lrwxr-xr-x   1 sebastian  staff     23  8 Jul 21:12 pecl -> /usr/local/lib/php/pecl
drwxr-xr-t   3 root       admin     96  3 Jul 13:30 sbin
drwxr-xr-x   4 sebastian  staff    128  3 Jul 13:30 share

In this case, pecl is symlinked to /usr/local/lib/php/pecl.

Now check the output of which pecl:

 % which pecl
/usr/local/bin/pecl

And then check /usr/local/bin/pecl:

ls -la /usr/local/bin/pecl

If it returns another path, remove the pecl symlink from the /usr/local/Cellar/php/7.3.7 folder:

rm /usr/local/Cellar/php/7.3.7/pecl

After removing the symlink, run pecl install xdebug again and the error should be gone.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top