How to debug php artisan serve in PHPStorm?

Debugging using php artisan serve does not work unless you have enabled debugging in ini file.

@Bogdan pointed out the reason. artisan serve will call PHP Built-in Web Server but does not pass on the php command line options (named interpreter options in PHPStorm).

i.e. if you execute from command line:

$ php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 artisan serve

Then these options given by -d are not passed to called PHP Built-in Web server. You can see the calling of built-in server here.

Workaround in PHPStorm is to create a Run configuration that calls PHP Built-in Web server directly. Instructions:

  1. Open Run -> Edit Configurations…
  2. Create new ‘PHP Built-in Web Server’
  3. Set values:
  • Host: localhost
  • Port: 8000
  • Document root: select Laravel’s public catalog/directory
  • Check Use route script and select server.php in Laravel projects root directory.
  • Interpreter options: -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1
  1. click OK and run.

Now the PHPStorm will execute same command as php artisan serve does with additional interpreter options. Actually the php artisan serve only purpose is to append the server.php to PHP Built-In Web Server. server.php just emulates Apache’s mod_rewrite functionality.

Update: Good reminder from @attila-szeremi: make sure “Start Listening for PHP Debug Connections” is enabled which you manually need to do if you don’t run a PhpStorm configuration with “Debug”

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)