Php – How to debug php artisan serve in PHPStorm

laravelPHPphpstormxdebug

I am using PHPStorm for develop my PHP web pages. All work fine with my Apache Server, XDebug, and a simple web PHP project. No problem.

But, when I try to debug a Laravel 5.1 Web Project using php artisan serve, I can't debug the breakpoints. It's like the php artisan serve use another server…

And on my PHPStorm, I always see:

Waiting for incoming connection with ide key '(randomNumberHere)'

I have configured all in PHPStorm (enabling remote debug, correct port, etc.), and with "normal" PHP projects all works fine.

Can someone tell me if I need to change something?

Thanks!

Best Answer

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"