This tutorial describes how to set up Xdebug in combination with Laravel Valet, PHP 7.4, and PHPStorm. The prerequisite is that Laravel Valet is installed as described here.
The first step is to prepare PECL:
pecl channel-update pecl.php.net ; pecl clear-cache
Now, we can install Xdebug:
pecl install xdebug
Next, restart Laravel Valet:
In the next step, we check if XDebug is installed correctly:
php -m | grep 'xdebug'
The output should contain
Now we need to find out if Xdebug is correctly included in the
php.ini file. Execute the following command:
The output provides the path to the
php.ini. In my case, it is:
At the beginning of the file, the following two lines should be present:
If these two lines are not present anywhere in the file, please add/modify them accordingly.
Then restart Valet again:
Next, you need to install a browser extension for Chrome or Firefox to enable browser output debugging. More information can be found here.
When debugging command-line scripts, debugging can be easily enabled in PHPStorm. When debugging local websites, you need to set a corresponding cookie using one of the browser extensions mentioned above. Then, debugging needs to be enabled in PHPStorm to debug the page accordingly.
Further information on this topic can be found in the corresponding PHPStorm documentation.