Xdebug 2
If you are using Xdebug 2 type this command in the terminal:
php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=on -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 artisan
followed by command, options and arguments.
For example, if you want to debug the inspire command you would type:
php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=on -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 artisan inspire
Xdebug 3
For Xdebug 3 type the following command:
php -dxdebug.start_with_request=yes -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 artisan
followed by command, options and arguments.
For inspire command you would type:
php -dxdebug.start_with_request=yes -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 artisan inspire
Dumb it down
Add a script in composer.json so you don’t have to write the whole Xdebug configuration every time you want to debug an artisan command.
"scripts": { // Xdebug 2 "artisan_xdebug2": "@php -dxdebug.remote_enable=1 -dxdebug.remote_autostart=on -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 artisan", // Xdebug 3 "artisan_xdebug3": "@php -dxdebug.start_with_request=yes -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 artisan", }
Name your script however you want, of course, then use it like:
composer artisan_xdebug2 inspire # or composer artisan_xdebug3 inspire
NOTE: Make sure the port matches your Xdebug configuration.