Setup Xdebug3 with PHP7.4, PHPStorm and Laravel Valet
This walkthru assumes that you have Laravel Valet, PHP7.4 installed. If not, follow these instructions.
Install Xdebug
-
Prepare Pecl
pecl channel-update pecl.php.net ; pecl clear-cache
-
Install Xdebug
pecl install xdebug
-
Restart Laravel Valet
valet restart
Let’s see what we got so far:
-
First check Xdebug is installed:
php -m
-
Check the paths to ini-files
php --ini
Your output should look something like this:
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,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
- Edit
/usr/local/etc/php/7.4/php.ini
and Add these lines to your
[xdebug]
zend_extension="xdebug.so" <-- Most likely already there
xdebug.mode=debug
xdebug.client_port="9003"
Please not that the new default port for Xdebug3 is 9003.
Important:
Restart Laravel Valet again.
valet restart
PHPStorm
Next we are going to configure PHPStorm 2020.3 to listen for Xdebug.
Open PHPStorm settings (cmd-,) and check your settings settings.
Languages & Frameworks > PHP > Debug
Make sure Xdebug is listening to port 9003 and ”Can accept external connections” is checked. I like these ones:
Click ”Start listening for debug connections”
Add a breakpoint and reload your page and it should hopefullt work :-)
Troubleshooting
Nothing happens
-
Make sure you have restarted Laravel Valet after installation.
-
Check that the IDE-key is set in your browser extension
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.