使用Homestead从PHPStorm调试laravel artisan [英] debugging laravel artisan from PHPStorm with homestead
问题描述
我设置了Laravel Homestead.然后,我同时配置了宅基 xdebug.ini 和 PHPStorm 来使调试工作正常.
I setup Laravel Homestead. I then configured both homestead xdebug.ini and PHPStorm to make the debugging work.
这是我在宅基地内的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"
要开始调试会话,请按照以下步骤操作
- 在PHPStorm中->开始侦听连接
- 在PHPStorm中设置一个断点
- 在我的浏览器中->使用XDebug Chrome Helper或添加到我的URL吗?XDEBUG_SESSION_START =
- 加载页面
这很好用.我的问题是当我在homestead命令行中并且运行php artisan
命令时,我无法使它达到断点.
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.
我尝试过的事情
-
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中被击中
I also tried to set xdebug.remote_autostart=On
then sudo service php5-fpm restart
but still my breakpoints never get hit in PHPStorm
推荐答案
有两点很重要:
-
remote_connect_back
在CLI情况下无法使用,因为当您在控制台中时Xdebug无法检测到远程IP - 在NAT网络配置中使用homestead/VirtualBox时,您的开发计算机(运行PHPStorm)没有从VM内部看到的IP
127.0.0.1
.取而代之的是,它通常具有类似于10.0.2.2
的IP.要找出正确的IP,请查看您Apache的access.log
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
,
以下内容对我有用:
php -dxdebug.remote_autostart=on -dxdebug.remote_connect_back=off
-dxdebug.remote_host=10.0.2.2 artisan
- edit 如果未命中断点,则必须正确设置文件夹映射(因为IDE中的路径与Web服务器看到的路径不同:
- 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:
-
在VM中执行
export PHP_IDE_CONFIG="serverName=yourservername"
,其中yourservername
是您在屏幕快照中名称"下配置的内容
Do
export PHP_IDE_CONFIG="serverName=yourservername"
in your VM, whereyourservername
is what you configured in the screenshot under "name"
使用IDE密钥和上面配置的服务器添加Php远程调试配置
Add a Php Remote Debug Configuration with an IDE key and the server configured above
并将您的IDE密钥和remote_host添加到VM的XDEBUG-CONFIG
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"
参考文献: http://randyfay.com/内容/远程命令行调试-phpstorm-phpdrupal-包括-drush
这篇关于使用Homestead从PHPStorm调试laravel artisan的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!