php 远程服务器的 Xdebug 未连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8049776/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:50:54  来源:igfitidea点击:

Xdebug for remote server not connecting

phpnetbeansxdebug

提问by Gruber

I want a team using different computers to be able to debug PHP on a remoteserver, but I am having a hard time getting Xdebug to work in NetBeans 7.0.1. I've tried many online tips, but to no avail.

我希望使用不同计算机的团队能够在远程服务器上调试 PHP ,但我很难让 Xdebug 在 NetBeans 7.0.1 中工作。我尝试了很多在线提示,但都无济于事。

For the record, I have successfully installed Xdebug locallyon a Windows 7 machine running WampServer. So I candebug PHP with breakpoints in NetBeans, provided I set the Project Properties->Run Configuration->Run Asproperty to Local Web Site. However, as stated above my goal is to debug in NetBeans on a Remote Web Site.

作为记录,我已经在运行 WampServer 的 Windows 7 机器上成功地本地安装了 Xdebug 。因此,我可以在 NetBeans 中使用断点调试 PHP,前提是我将Project Properties->Run Configuration->Run As属性设置为Local Web Site。但是,如上所述,我的目标是在远程网站上的 NetBeans 中进行调试。

My server is a Ubuntu 11.04 machine. I have used the output from http://www.xdebug.org/find-binary.phpto put the proper binary on the machine. I have modified all php.inifiles I could find (in both the php5/apache2and php5/clidirectories) to include these lines:

我的服务器是 Ubuntu 11.04 机器。我已经使用http://www.xdebug.org/find-binary.php的输出将正确的二进制文件放在机器上。我已经修改了php.ini我能找到的所有文件(在php5/apache2php5/cli目录中)以包含这些行:

zend_extension="/usr/lib/php5/20090626+lfs/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000

If I check the phpinfo.phpweb page, it says:

如果我查看phpinfo.php网页,它会说:

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans

So Xdebug does seem to be installed properly. Still, when I try debugging in NetBeans, I get the endless status bar message Waiting For Connection (netbeans-xdebug). When I hit the stop button I get No connection from xdebug was detected within X seconds. The reason could be that xdebug is not installed or not properly configured.

所以 Xdebug 似乎安装正确。尽管如此,当我尝试在 NetBeans 中调试时,我收到了无休止的状态栏消息Waiting For Connection (netbeans-xdebug)。当我点击停止按钮时,我在 X 秒内没有检测到来自 xdebug 的连接。原因可能是未安装 xdebug 或未正确配置

Maybe I'm confusing local settings with server settings here? A postsaid xdebug.remote_hostshould be set to the IP of the machine running NetBeans, but I want a team to be able to debug using machines with different IP addresses. A problem could be port 9000, but I have checked that it is not blocked.

也许我在这里混淆了本地设置和服务器设置?一个帖子xdebug.remote_host应该设置为运行 NetBeans 的机器IP,但我希望团队能够使用具有不同 IP 地址的机器进行调试。问题可能是端口 9000,但我已经检查过它没有被阻止。

Any help that could clarify this would be appreciated!

任何可以澄清这一点的帮助将不胜感激!

回答by Linus Kleen

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

运行 PHP(和 XDebug)的服务器需要能够连接到您的工作站/桌面。

Diagram

图表

So you'll need the server set up accordingly by either telling it to connect to a specificIP-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.

因此,您需要通过告诉服务器连接到特定IP 地址 ( xdebug.remote_host) 或自动“连接回” ( xdebug.remote_connect_back) 来相应地设置服务器。不过,后者有一些安全隐患。这些在手册中有概述。

回答by medium8

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

对我来说,xdebug.remote_connect_back = On不起作用。我所做的是在我的客户端机器上设置 ssh 端口转发。

xdebug config on the remote machine:

远程机器上的 xdebug 配置:

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.

必须允许远程机器上的 shell 访问。

回答by álvaro González

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.

这允许 Web 服务器连接到任何要求调试会话的计算机。这样您就不必对 IP 地址进行硬编码并且能够共享 Xdebug。该指令在早期版本中不存在,并且经常从教程和文档中省略。

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

您还需要验证每台客户端计算机都接受到端口 9000 ( xdebug.remote_port) 的传入连接。这包括配置防火墙并确保调试器客户端启动并运行

回答by Asaf Hananel

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'

注意:即使由于 'xdebug.remote_autostart=1' 不存在 GET/POST/COOKIE 变量,调试器也会工作

回答by Jules Colle

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.

我在尝试配置 docker 时遇到过几次同样的问题,在多次挠头之后我意识到这是解决它的方法。所以我决定把它放在这里作为我未来的自己的答案。

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

大多数情况下,Dockerfile 会将此语句添加到 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.

这会导致一切看起来都很好,但不知何故,PHP 风暴实际上没有捕获任何调试连接。用以下内容替换上面的行立即为我解决了问题。

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 buildand $ docker-compose up -d

当然,在那之后你仍然需要运行: $ docker-compose down$ docker-compose build$ docker-compose up -d

回答by Dmitry Davydov

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

感谢xdebug.remote_connect_back = On服务器端的 php.ini
另外我必须在Chrome 中使用这个插件才能在 PhpStorm 中开始调试会话

回答by beto.bateria

You will need set:

您将需要设置:

xdebug.remote_host=192.168.1.104

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

192.168.1.104是客户端的 ip,您在其中使用 IDE

回答by Abdul Munim

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 .PHPrather starting up with .HTML.

您要启动哪个页面扩展来开始调试?我记得我疯了,度过了不眠之夜,XDebug 的所有设置都很顺利。问题是,我不开机.PHP,而与启动.HTML

If you are then try starting up your debugging with .PHPfile.

如果您尝试使用.PHP文件启动调试。