Run PHP with debugger

#!/bin/bash if [[ ! $(dpkg -s php-xdebug | grep installed) ]] then sudo apt --yes install php-xdebug # Disable by default. sudo phpdismod xdebug fi php -dzend_extension=xdebug.so -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 -dxdebug.remote_autostart=1 "$@"
In PhpStorm, in order to step-debug PHP scripts run from command line,
1) activate `Run -> Start Listening for PHP Debug Connections`,
2) set a breakpoint somewhere useful,
3) run the script using `php_debug` instead of `php` (if you save the above code as a script ~/bin/php_debug), for example:

`php_debug artisan starmap-product-variant:add --id=6973630316603 --properties='{"design":"green","flip-colours":null}'`
or
`php_debug /var/www/print/public/bin/magento module:enable Magento_Bundle`

It just works, without any additional configuration.
Or, at least, it worked in all the environments I tested (namely, two similar Ubuntu-like Linux environments).

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.