Xdebug for remote server not connecting

和自甴很熟 提交于 2019-11-28 03:15:53
Linus Kleen

The server running PHP (and XDebug) needs to be able to connect to your workstation/desktop.

So you'll need the server set up accordingly by either telling it to connect to a specific IP-address (xdebug.remote_host) or to automatically "connect back" (xdebug.remote_connect_back). The latter has some security implications, though. These are outlined in the manual.

The key directive is this:

xdebug.remote_connect_back = On

This allows the web server to connect to whatever computer is asking for a debugging session. This way you don't have to hard-code an IP address and are able to share Xdebug. This directive was not present in earlier versions and is often omitted from tutorials and documentation.

You also need to verify that every client computer accepts incoming connections to port 9000 (xdebug.remote_port). This includes configuring the firewall and making sure the debugger client is up and running

medium8

For me, xdebug.remote_connect_back = On does not work. What I did was to set ssh port forwarding on my client machine.

xdebug config on the remote machine:

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

forward ports on the client machine:

ssh -g -N -lusername -R9000:127.0.0.1:9000 [remote.host.ip]

The shell access on the remote machine must be allowed.

In my case, those commands helped me:

xdebug.remote_enable = On
xdebug.remote_autostart=1

Notice: the debugger will work even if GET/POST/COOKIE variable is not present because of 'xdebug.remote_autostart=1'

Thanks for xdebug.remote_connect_back = On on server side php.ini
Also I had to use this plugin for Chrome to be able to start debugging session in PhpStorm

I had the same issue a couple of times while trying to configure docker and after scratching my head multiple times I realized this was the way to fix it. So I decided to put this here as an answer for my future self.

Most of the time the Dockerfile was adding this this statement to php.ini:

xdebug.remote_connect_back     = on

This would cause everything to seem okay but somehow no debug connections were actually caught by PHP storm. Replacing the line above with the following instantly fixes stuff for me.

xdebug.remote_connect_back     = 0
xdebug.remote_host             = host.docker.internal

Of course, after that you still need to run: $ docker-compose down $ docker-compose build and $ docker-compose up -d

What page extension are you firing up to start debugging? I remember I went nuts and spent sleepless nights where all settings with XDebug are going great. The problem was I was not starting up with .PHP rather starting up with .HTML.

If you are then try starting up your debugging with .PHP file.

beto.bateria

You will need set:

xdebug.remote_host=192.168.1.104

192.168.1.104 is the client's ip, where you working with the IDE

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