Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
698 views
in Technique[技术] by (71.8m points)

vagrant - debugging laravel artisan from PHPStorm with homestead

I setup Laravel Homestead. I then configured both homestead xdebug.ini and PHPStorm to make the debugging work.

Here is my xdebug.ini inside homestead

zend_extension=xdebug.so
xdebug.remote_autostart = on
xdebug.remote_enable = on
xdebug.remote_connect_back = on
xdebug.remote_port = 9000
xdebug.idekey = "vagrant"

To start a debugging session the steps I follow are

  1. In PHPStorm --> Start Listening for connections
  2. In PHPStorm set a breakpoint
  3. In my browser --> Use XDebug Chrome Helper OR add to my URL ?XDEBUG_SESSION_START=
  4. Load the page

This works perfectly. My problem is when I'm inside homestead command line and I run a php artisan command then I can't get it to hit my breakpoints.

What I've tried

  1. XDEBUG_CONFIG="idekey=PHPSTORM" PHP_IDE_CONFIG="serverName=server_name" php -dxdebug.remote_host="127.0.0.1" artisan mycommand

  2. php -d xdebug.profiler_enable=On artisan mycommand

  3. I also tried to set xdebug.remote_autostart=On then sudo service php5-fpm restart but still my breakpoints never get hit in PHPStorm

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Two things are important:

  1. remote_connect_back can not work in the CLI case because Xdebug can not detect the remote IP when you are in the console
  2. When using homestead / VirtualBox in the NAT network configuration, your development machine (which is running PHPStorm) does not have the IP 127.0.0.1 seen from inside the VM. Instead, it has usually an IP like 10.0.2.2. To find out the correct IP, have a look at your Apache's access.log,

The following worked for me:

php -dxdebug.remote_autostart=on -dxdebug.remote_connect_back=off 
  -dxdebug.remote_host=10.0.2.2 artisan
  1. edit If your breakpoints are not hit, you have to set up the folder mappings correctly (as your path in the IDE is different from what the web server sees:

Folder Mappings

  1. Do export PHP_IDE_CONFIG="serverName=yourservername" in your VM, where yourservername is what you configured in the screenshot under "name"

  2. Add a Php Remote Debug Configuration with an IDE key and the server configured above Debug Configuration

  3. And add your IDE key and the remote_host to the VM's XDEBUG-CONFIG

    export XDEBUG_CONFIG="idekey=artisan remote_host=10.0.2.2"

References: http://randyfay.com/content/remote-command-line-debugging-phpstorm-phpdrupal-including-drush


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...