Setting up XDebug with PHPStorm and Valet Development Environment

Preparation:

  1. Homebrew should be installed
  2. Valet should be installed and running: https://laravel.com/docs/7.x/valet
  3. Browser extension for PHPSTORM should be installed: https://www.jetbrains.com/help/phpstorm/browser-debugging-extensions.html
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
Remedy:
gerry@webgarten ~ % mkdir -p /usr/local/lib/php/pecl
gerry@webgarten ~ % pecl install xdebug
Installing '/usr/local/Cellar/php/7.4.7/pecl/20190902/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.9.6
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,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.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:
zend_extension="xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=1

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!

 

See also

Shortcode E-Mail Obfuscator

The following shortcode snippet is useful for disguising emails to protect them from SPAM. Please note that this method only works if Javascript is activated. In addition, there is no 100%igen protection against bots,...

Elementor popup / flyout menu no longer closes for mobile view

Elementor: Version 3.72 Behaviour: An Elementor popup opens, but no longer closes (when clicking on icon or Esc or other triggers). If you look in the source code, you will find the Javascript error message: "Elementor t.entrance_animation_duration is undefined" Cause:...

PHPStorm: Local Changelist in Git Tool disappeared

Problem: Local Change List under PHPStorm is missing in the Git Tool Solution: From time to time I had the phenomenon that the Local Changelist (the files in my version control) were not visible as tabs in the Git tool....

Variable not available in blade component

Problem: The parameter transfer of a blade attribute does not work, the variable in the component is empty. There is no error message, but the variable does not appear to have been passed. Solution: The error may lie in the usage...

WP CLI Error: Error establishing a database connection.

Appearance: Submitting commands via WP CLI, but WordPress in the browser works. This error often occurs when the WP CL interpreter cannot correctly interpret the database connection in wp-config.php. Solution: In 99% of all cases the...

Convert Px to SEM / EM very quickly with Alfred

Auf dem Mac gibt es einen wunderbaren Alfred-Workflow, der Px in Rem umrechnet: Download Direktlink: https://raw.githubusercontent.com/vitorgalvao/requested-alfred-workflows/master/Workflows/Px%20Rem%20Em.alfredworkflow Einfach installieren, dann CMD-Space: Alfred Bar "pxrem" tippen und die Zahl in Pixel angeben. Die Umrechnung in REM wird…