使用 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
debugging laravel artisan from PHPStorm with homestead
提问by user391986
I setup Laravel Homestead. I then configured both homestead xdebug.iniand PHPStormto make the debugging work.
我设置了 Laravel Homestead。然后我配置了 homestead xdebug.ini和PHPStorm以使调试工作。
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
要开始调试会话,我遵循的步骤是
- In PHPStorm --> Start Listening for connections
- In PHPStorm set a breakpoint
- In my browser --> Use XDebug Chrome Helper OR add to my URL ?XDEBUG_SESSION_START=
- Load the page
- 在 PHPStorm --> 开始监听连接
- 在 PHPStorm 中设置断点
- 在我的浏览器中 --> 使用 XDebug Chrome Helper 或添加到我的 URL ?XDEBUG_SESSION_START=
- 加载页面
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.
这完美地工作。我的问题是当我在 homestead 命令行中运行一个php artisan
命令时,我无法让它达到我的断点。
What I've tried
我试过的
XDEBUG_CONFIG="idekey=PHPSTORM" PHP_IDE_CONFIG="serverName=server_name" php -dxdebug.remote_host="127.0.0.1" artisan mycommand
php -d xdebug.profiler_enable=On artisan mycommand
I also tried to set
xdebug.remote_autostart=On
thensudo service php5-fpm restart
but still my breakpoints never get hit in PHPStorm
XDEBUG_CONFIG="idekey=PHPSTORM" PHP_IDE_CONFIG="serverName=server_name" php -dxdebug.remote_host="127.0.0.1" artisan mycommand
php -d xdebug.profiler_enable=On artisan mycommand
我也尝试设置
xdebug.remote_autostart=On
然后sudo service php5-fpm restart
,但仍然是我的断点永远不会打PHPStorm
回答by Alex
Two things are important:
有两点很重要:
remote_connect_back
can not work in the CLI case because Xdebug can not detect the remote IP when you are in the console- 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 like10.0.2.2
. To find out the correct IP, have a look at your Apache'saccess.log
,
remote_connect_back
无法在 CLI 情况下工作,因为当您在控制台中时,Xdebug 无法检测到远程 IP- 在 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
- 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:
- 编辑如果您的断点未命中,您必须正确设置文件夹映射(因为您在 IDE 中的路径与 Web 服务器看到的不同:
Do
export PHP_IDE_CONFIG="serverName=yourservername"
in your VM, whereyourservername
is what you configured in the screenshot under "name"Add a Php Remote Debug Configuration with an IDE key and the server configured above
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"
export PHP_IDE_CONFIG="serverName=yourservername"
在你的虚拟机中做,你yourservername
在“名称”下的截图中配置的内容在哪里添加一个带有IDE密钥的Php远程调试配置和上面配置的服务器
并将您的 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');