调试远程 PHP CLI 脚本
这是我的情况:
我正在使用带有 RSE 插件的 Eclipse IDE 在远程服务器上开发 PHP CLI 脚本(允许直接在服务器上编辑文件)。
现在我需要以与 Java 类似的方式调试这些脚本(断点、显示变量内容……)。
我找到了可以完成这项工作的东西:XDebug 和 PDT(Eclipse 插件)。问题是,当我尝试启动调试模式时,Eclipse 说本地计算机上没有 PHP 调试器。我想它应该安装在服务器计算机上。
我想知道是否可以使用 PDT 和 XDebug 来调试远程脚本,如果是这样,如何配置它们来执行此操作。如果没有,我想知道是否存在其他解决方案。看起来 XDebug 使用 TCP,因此应该可以远程调试。如果需要的话我可以改变我的IDE。
服务器运行带有 php5-cli 的 Ubuntu 10.04,带有 eclipse 的开发机器运行 Win7 32 位。
谢谢
Here is my situation:
I am developing PHP CLI scripts on a distant server using Eclipse IDE with the RSE plugin (allows to edit files directly on the server).
Now I need to debug these scripts in a similar fashion than in Java (break points, show the variables content, ...).
I found something that could do the job: XDebug and PDT (Eclipse plugin). The problem is that when I try to launch the debug mode Eclipse says that there is no PHP debugger on the local machine. I guess it should be installed on the server machine.
I would like to know if it's possible to use PDT and XDebug to debug remote scripts and, if it's the case, how to configure them to do so. If not, I'd like to know if other solutions exist. It seems like XDebug uses TCP so it should be possible to debug remotely. I can change my IDE if necessary.
The server runs Ubuntu 10.04 with php5-cli and the dev machine with eclipse runs Win7 32bit.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,这是可能的,您需要在远程服务器的 PHP.ini 文件中启用 xdebug,并确保 xdebug 端口(默认 9000)未被任何防火墙阻止。
有关设置远程调试的 xdebug 页面。
Yes this is possible, you need to enable xdebug in the remote server's PHP.ini file and make sure that the xdebug port (default 9000) is not blocked by any firewalls.
xdebug's page on setting up remote debugging.
对于遇到同样问题的人来说,以下是完整的过程:
首先,按照以下网站上的说明安装 RSE: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.rse.doc.user /gettingstarted/g1installing.html
按照此 HowTo 中的说明在服务器上安装 XDebug:
http://ubuntuforums.org/showthread.php?t=525257
在 Eclipse 上安装 PDT并进行以下更改:
- 在 Windows/Preferences 下,进入 PHP/Debug 并将 PHP Debugger 更改为 XDebug
- 在 Windows/Preferences 下,进入 PHP/Debug/Installed Debuggers 并配置 XDebug。将字段“接受远程会话 (JIT)”更改为“任意”。
打开远程系统资源管理器透视图,选择脚本目录并从中创建一个项目(右键单击,创建远程项目)。它现在将出现在 PHP 透视图中。
让 Eclipse 运行并访问服务器(例如通过 SSH)。运行您要调试的脚本。然后 Eclipse 上将出现一个窗口,建议您选择要将运行脚本链接到哪个“本地”(在我们的示例中通过 RSE 远程)文件。通常,建议的默认脚本应该是正确的,因为它是在服务器上运行的脚本。
您现在应该可以使用 Eclipse 对 PHP-CLI 脚本进行可视化调试!
Here is the complete procedure for the people who have the same problem:
First, install RSE by following the instructions on this website: http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.rse.doc.user/gettingstarted/g1installing.html
Follow the instructions on this HowTo to install XDebug on the server:
http://ubuntuforums.org/showthread.php?t=525257
Install PDT on Eclipse and do the following changes:
- under Windows/Preferences, go under PHP/Debug and change PHP Debugger to XDebug
- under Windows/Preferences, go under PHP/Debug/Installed Debuggers and configure XDebug. Change the field "Accept remote session (JIT)" to "any".
Open the Remote System Explorer perspective, select your scripts directories and create a project from them (Right Click, Create Remote Project). It will now appear in the PHP perspective.
Let Eclipse run and go to the server (e.g. via SSH). Run the script you want to debug. A Window will then appear on Eclipse proposing you to choose with which "local" (remote via RSE in our case) file you want to link the running script to. Normally, the default script proposed should be the correct one, because it is the one running on the server.
You should now have visual debugging with Eclipse for your PHP-CLI scripts!
您想要在调试的同时能够与 CLI 上的脚本交互,还是只想启动它然后单步执行代码?我猜你的问题是指无法通过 URL 直接访问脚本的问题。如果这是您的问题,那么我想最简单的解决方案是调试需要您的脚本的常用 PHP 网站。然后,您可以首先通过该网站启动 XDebug,并通过 require/include 语句单步执行脚本。
index.php:
最诚挚的问候
拉斐尔
Do you want to debug while being able to interact with the script on CLI or do you just want to start it and then step through the code? I guess your question is referring to the problem that you can't access the script directly through a URL. If that's your problem, then I guess the easiest solution would be to debug a usual PHP-web-site which requires your script. Then you can launch XDebug with that web-site initially and step into the script through the require/include-statement.
index.php:
Best regards
Raffael