简体   繁体   English

phpstorm和docker中的xdebug

[英]xdebug in phpstorm and docker

I managed to get xdebug in combination with docker and phpstorm. 我设法将xdebug与docker和phpstorm结合使用。 For http calls...IE 对于http呼叫... IE

http://192.168.99.100:8081/?XDEBUG_SESSION_START=PHPSTORM http://192.168.99.100:8081/?XDEBUG_SESSION_START=PHPSTORM

But when I try to run my phpunit tests, It does not connect with phpstorm 但是,当我尝试运行phpunit测试时,它无法与phpstorm连接

I did the correct directory mapping right in phpstorm, and also ran the following on my docker-instance export XDEBUG_CONFIG="idekey=PHPSTORM" 我在phpstorm中进行了正确的目录映射,并且还在我的export XDEBUG_CONFIG="idekey=PHPSTORM" -instance export XDEBUG_CONFIG="idekey=PHPSTORM"上运行了以下内容

I also tried on my docker: export PHP_IDE_CONFIG='serverName=web.docker'and named the server config on phpstorm web.docker . 我也在docker上尝试过:export PHP_IDE_CONFIG ='serverName = web.docker'并在phpstorm web.docker上命名服务器配置。 still working over http but not CLI 仍然可以通过http而不是CLI进行工作

So can I get phpstorm and xdebug working together for command line too? 那么我也可以让phpstorm和xdebug一起为命令行工作吗?

here is my file: /etc/php5/cli/conf.d/20-xdebug.ini 这是我的文件: /etc/php5/cli/conf.d/20-xdebug.ini

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM
xdebug.remote_connect_back=1
xdebug.remote_host=172.17.42.1
dxdebug.remote_autostart=1

When I turn on logging, and play with the xdebug_remote_host IP adress I get 当我打开日志记录并使用xdebug_remote_host IP地址时,我得到了

W: Remote address not found, connecting to configured address/port: localhost:9000. :-|
E: Could not connect to client. :-(
Log closed at 2015-10-13 12:20:39

Log opened at 2015-10-13 12:22:58
I: Checking remote connect back address.
W: Remote address not found, connecting to configured address/port: 172.17.42.1:9000. :-|
E: Could not connect to client. :-(
Log closed at 2015-10-13 12:22:58

Log opened at 2015-10-13 12:23:58
I: Checking remote connect back address.
W: Remote address not found, connecting to configured address/port: 192.168.99.100:9000. :-|
E: Could not connect to client. :-(
Log closed at 2015-10-13 12:23:58

Solution (edit) By turning on the xdebug logging, I saw it was succesfully connecting to 192.168.99.1 so this solved the issue 解决方案(编辑)通过打开xdebug日志记录,我看到它成功连接到192.168.99.1因此这解决了问题

xdebug.remote_host=192.168.99.1

Two things come to my mind right now: 我现在想到两件事:

  1. Is xdebug.remote_host set correctly? xdebug.remote_host设置正确吗? For the HTTP Link you provided a 192.168. 对于HTTP链接,您提供了192.168. address, for the way back it's a 172.17. 地址,回程是172.17. address. 地址。 Can you ping your host on that IP? 您可以在该IP上ping您的主机吗?

  2. In your ini file it reads: 在您的ini文件中,其内容为:

     dxdebug.remote_autostart=1 

    Is this just a typo here, or is that actually in your config file? 这只是这里的错字,还是实际上在您的配置文件中? Because it should read xdebug without the "d" in front of it. 因为它应该读取xdebug而不在其前面加上“ d”。 It should be: 它应该是:

     xdebug.remote_autostart=1 

    You should only add the d when you add the option when executing the script like this: 仅在执行以下脚本时添加选项时才添加d:

     php -dxdebug.remote_autostart=1 script.php 

If that doesn't help yet, please enable the remote log by adding something like this to the config: 如果仍然不能解决问题,请通过向配置中添加如下内容来启用远程日志:

xdebug.remote_log = /var/log/xdebug_remote.log

maybe that'll help to find the problem. 也许这将有助于发现问题。

What worked for me is ssh tunnel with this configuration xdebug.remote_connect_back=0 xdebug.remote_host=127.0.0.1 对我有用的是使用此配置的ssh隧道xdebug.remote_connect_back = 0 xdebug.remote_host = 127.0.0.1

See: Xdebug with SSH tunnel on Docker for Mac 请参阅: Mac的Docker上具有SSH隧道的Xdebug

Since Docker-17.06, you can access services hosted on Mac inside Container, via the static host name: docker.for.mac.localhost 从Docker-17.06开始,您可以通过静态主机名访问Container内Mac上托管的服务: docker.for.mac.localhost

full answer is here: https://stackoverflow.com/a/48495802/1241980 完整的答案在这里: https : //stackoverflow.com/a/48495802/1241980

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM