使用 homestead 从 PHPStorm 调试 laravel artisan

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27936323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:41:05  来源:igfitidea点击:

debugging laravel artisan from PHPStorm with homestead

laravelvagrantxdebuglaravel-routinghomestead

提问by user391986

I setup Laravel Homestead. I then configured both homestead xdebug.iniand PHPStormto make the debugging work.

我设置了 Laravel Homestead。然后我配置了 homestead xdebug.iniPHPStorm以使调试工作。

Here is my xdebug.ini inside homestead

这是我在宅基地内的 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"

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

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

这完美地工作。我的问题是当我在 homestead 命令行中运行一个php artisan命令时,我无法让它达到我的断点。

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=Onthen sudo service php5-fpm restartbut still my breakpoints never get hit in PHPStorm

  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

回答by Alex

Two things are important:

有两点很重要:

  1. remote_connect_backcan 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.1seen 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,
  1. remote_connect_back无法在 CLI 情况下工作,因为当您在控制台中时,Xdebug 无法检测到远程 IP
  2. 在 NAT 网络配置中使用 homestead / VirtualBox 时,您的开发机器(运行 PHPStorm)没有127.0.0.1从 VM 内部看到的 IP 。相反,它通常具有像10.0.2.2. 要找出正确的 IP,请查看您的 Apache 的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. editIf 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:
  1. 编辑如果您的断点未命中,您必须正确设置文件夹映射(因为您在 IDE 中的路径与 Web 服务器看到的不同:

Folder Mappings

文件夹映射

  1. Do export PHP_IDE_CONFIG="serverName=yourservername"in your VM, where yourservernameis 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"

  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"

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

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

回答by Sabrina Leggett

Or, if that all is just too complicated or not working - you can trigger your artisan command via a url (route)using

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

Artisan::call('whatever:command');