从PHPStorm调试laravel工匠与宅基地

use*_*986 15 xdebug vagrant laravel laravel-routing homestead

我设置了Laravel Homestead.然后我配置了宅基地xdebug.iniPHPStorm以使调试工作.

这是我家园内的xdebug.ini

zend_extension=xdebug.so
xdebug.remote_autostart = on
xdebug.remote_enable = on
xdebug.remote_connect_back = on
xdebug.remote_port = 9000
xdebug.idekey = "vagrant"
Run Code Online (Sandbox Code Playgroud)

要开始调试会话,我遵循的步骤是

  1. 在PHPStorm中 - >开始侦听连接
  2. 在PHPStorm中设置一个断点
  3. 在我的浏览器中 - >使用XDebug Chrome Helper或添加到我的URL?XDEBUG_SESSION_START =
  4. 加载页面

这非常有效.我的问题是当我进入宅基地命令行并且我运行一个php artisan命令然后我无法让它达到我的断点.

我试过的

  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. 我也试着设置xdebug.remote_autostart=On,然后sudo service php5-fpm restart,但仍然是我的断点永远不会打PHPStorm

Ale*_*lex 25

有两件事很重要:

  1. remote_connect_back 无法在CLI情况下工作,因为当您在控制台中时,Xdebug无法检测到远程IP
  2. 在NAT网络配置中使用homestead/VirtualBox时,您的开发计算机(运行PHPStorm)没有127.0.0.1从VM内部看到的IP .相反,它通常有像IP一样10.0.2.2.要找到正确的IP,请查看您的Apache access.log,

以下对我有用:

php -dxdebug.remote_autostart=on -dxdebug.remote_connect_back=off 
  -dxdebug.remote_host=10.0.2.2 artisan
Run Code Online (Sandbox Code Playgroud)
  1. 编辑如果未命中断点,则必须正确设置文件夹映射(因为IDE中的路径与Web服务器看到的路径不同:

文件夹映射

  1. 不要export PHP_IDE_CONFIG="serverName=yourservername"在你的虚拟机,在这里yourservername是你的截图在"名称"配置了什么

  2. 使用IDE密钥和上面配置的服务器添加Php远程调试配置 调试配置

  3. 并将您的IDE密钥和remote_host添加到VM的XDEBUG-CONFIG

    export XDEBUG_CONFIG="idekey=artisan remote_host=10.0.2.2"

参考文献:http://randyfay.com/content/remote-command-line-debugging-phpstorm-phpdrupal-including-drush


Sab*_*ett 14

或者,如果这一切都太复杂或不起作用 - 您可以使用网址(路线)触发您的工匠命令

Artisan::call('whatever:command');
Run Code Online (Sandbox Code Playgroud)