How to debug Artisan with Xdebug?

-

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.

Share this article

Recent posts

How to debug Artisan with Xdebug?

Xdebug 2 If you are using Xdebug 2 type this command in the terminal: php...

Extract Untranslated Strings from Laravel Projects using Localizator

Localizator is a small tool for Laravel that gives you the ability to extract untranslated strings from project files. It works using...

Use Laravel’s default translation strings in JavaScript

There are many great Laravel packages that offer ways to use Larave's translation strings in front-end, like mariuzzo/laravel-js-localization and thepinecode/i18n, but what...

How to Run Laravel Using Multiple Database Connections on the Fly

Recently I've found myself in a scenario where I had to run multiple database connections in a single Laravel application. Pretty easy...

Popular categories

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent comments