Vagrant + Xdebug + Atom

▼魔方 西西 提交于 2019-12-31 07:11:05

问题


I have a vagrant box with xdebug installed, running on OSX, but Im struggling to get the Atom xdebug plugin (php-debug) to connect to it.

I pasted the phpinfo(); data into the xdebug validation site and it said all was good. And you can see all the xdebug settings.

I have mapped port 9000 in the vagrant file.

config.vm.network :forwarded_port, guest: 9000, host: 9000

The vagrant box has host only network that exposes 192.168.10.100 as the IP of the server.

And I've tried all manner of different xdebug options, the ones on the ATOM plugin site suggest..

xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true

But that is a slightly confusing as remote_connect_back=1 means xdebug will ignore the remote_host setting - so not sure why both are in there - neither work.

I've restarted apache / php after each time I change the options, and check they are loaded with phpinfo();

If I check who is listening on port 9000

COMMAND     PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Atom\x20H 10656 Matt   28u  IPv6 0x321cb0a96ba5b593      0t0  TCP *:cslistener (LISTEN)
VBoxHeadl 10889 Matt   19u  IPv4 0x321cb0a981a71433      0t0  TCP *:cslistener (LISTEN)

You can see both vagrant (virtual box) and Atom. Although Atom is IPv6 which is odd....

But enabling the debugger in ATOM, setting a breakpoint and hitting the site, nothing happens - ATOM never connects.

Any ideas? Anyone got this to work?


回答1:


But that is a slightly confusing as remote_connect_back=1 means xdebug will ignore the remote_host setting

You are correct -- that option is not needed there -- it better be set to 0

xdebug.remote_host=127.0.0.1

This is wrong (unless you will be doing debugging via SSH tunnel). It must be an IP where debug client (Atom in your case) is running. It's xdebug who connects to client and NOT other way around: https://xdebug.org/docs/remote

This also means that the IP must be as seen from that Vagrant machine. Possibly the easiest way of getting it -- look at what $_SERVER['REMOTE_ADDR'] has.

I have mapped port 9000 in the vagrant file.

config.vm.network :forwarded_port, guest: 9000, host: 9000

You do not need to expose 9000 port in Vagrant -- nobody will be connecting to it (like you do with port 80 for web server) -- it's xdebug from VM/guest OS will be connecting outside to your "real"/host OS.

If anything -- you should be allowing outgoing connections on that port instead of incoming.

If I check who is listening on port 9000

This one means that Atom is unable to receive incoming xdebug connection over TCPv4 .. which xdebug will try to use by default (unless you specify IPv6 address in xdebug.remote_host).


If anything -- collect xdebug log (xdebug.remote_log) and see where it tries to connect etc.




回答2:


@LazyOne already answered this question, but issue I had was caused by antivirus (MCAfee) which was blocking incoming traffic. Maybe this will help someone in the future.



来源:https://stackoverflow.com/questions/42254964/vagrant-xdebug-atom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!