Xdebug for remote server not connecting

Gruber picture Gruber · Nov 8, 2011 · Viewed 62.8k times · Source

I want a team using different computers to be able to debug PHP on a remote server, 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.

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

My server is a Ubuntu 11.04 machine. I have used the output from http://www.xdebug.org/find-binary.php to put the proper binary on the machine. I have modified all php.ini files I could find (in both the php5/apache2 and php5/cli directories) to include these lines:

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.php web page, it says:

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.

Maybe I'm confusing local settings with server settings here? A post said xdebug.remote_host should 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.

Any help that could clarify this would be appreciated!

Answer

Linus Kleen picture Linus Kleen · Nov 8, 2011

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

Diagram

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.