Xdebug for remote server not connecting
PhpNetbeansXdebugPhp Problem Overview
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!
Php Solutions
Solution 1 - Php
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.
Solution 2 - Php
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.
Solution 3 - Php
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
Solution 4 - Php
Xdebug 3 upgrade guide for remote debugging
Summary of: https://xdebug.org/docs/upgrade_guide
Required PHP configuration changes/additions:
- remove
xdebug.
(remote_enable
|default_enable
|profiler_enable
|auto_trace
|coverage_enable
) - add
xdebug.mode=debug
OR usedevelop
|coverage
|gcstats
|profile
- add
xdebug.start_with_request=yes
xdebug.remote_autostart
is replaced byxdebug.mode=debug
withxdebug.start_with_request=yes
xdebug.remote_host
is replaced byxdebug.client_host
xdebug.remote_port
is replaced byxdebug.client_port
OR use new default in IDE setting (more below)
Example new configuration
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.idekey=myKey
xdebug.client_host=x.y.z.a
xdebug.remote_handler=dbgp
Where
x.y.z.a
= your IDE hostmyKey
= your configured key in the IDE
Required IDE configuration changes/additions:
- set
remote_port
to9003
(xdebug's new default port) OR setxdebug.client_port
to9000
in the configuration above to keep the old default
Solution 5 - Php
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'
Solution 6 - Php
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
Note: on Linux host.docker.internal
will not work. You can use 172.17.0.1
instead. (Note it is not 127.0.0.1, I always thought it was because I'm a bit dyslectic)
Solution 7 - Php
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
Solution 8 - Php
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
Solution 9 - Php
If you are using xdebug 3, you need to know that some variables are renamed. Read this: https://xdebug.org/docs/upgrade_guide
php.ini configuration wich worked for me:
[xdebug]
xdebug.mode=debug
zend_extension="C:/wamp64/bin/php/php7.4.26/ext/php_xdebug.dll"
xdebug.idekey=PHPSTORM
xdebug.client_host= "localhost"
xdebug.client_port=9003
Solution 10 - Php
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.
Solution 11 - Php
Very correct answer by Brad for xdebug 3; Thanks... In my case I had Win 10 with Php7.3.13, Netbeans 8.2 and IIS 10(eindia.com is one among many websites ) (browsers are Chrome with netbeans extension & FF)... and no Xampp, Wampp, Lampp... Then I installed xdebug(using wizard) and config as below:
[xDebug]
zend_extension = "C:\Program Files\PHP\v7.3\ext\php_xdebug-3.0.2-7.3-vc15-nts-x86_64.dll"
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_handler="dbgp"
xdebug.client_host="eindia.com"
;xdebug.remote_host=192.168.1.5
;xdebug.remote_connect_back=1
xdebug.client_port=9003
;xdebug.remote_mode=req
xdebug.idekey="netbeans-xdebug"
and its working like charm.