Nima
Nima

Reputation: 11

XDebug not connecting on remote server (VSCode+php-debug+Remote SSH on local machine)

I'm trying to set up a remote debugging with VSCode, php-debug extension, Remote SSH on my local machine and XDebug + PHP 7.3 on the remote machine. Using Remote SSH I can successfully connect to the remote machine, browse and edit code. I have two mode of debugging on my launch.json: 1) Launch on current script; 2) Listen for Xdebug. When I try to debug a code on the remote machine with the 1st method it works just fine. I can see the php-debug log on my current machine and also the xdebug log on the remote machine. But when I start the the debugger on Listen for XDebug mode on VS Code, it looks like it starts to listen. But when I load the site on the browser it does not stop on the breakpoint. Nothing is also logged in the xdebug log.

This is how my launch.json looks like

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9002,
        "log": true
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9002,
        "log": true
    }
]

}

and this is my xdebug config on the remote server

[XDebug]
zend_extension = "/opt/remi/php73/root/usr/lib64/php/modules/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_log="/tmp/xdebug.log"
xdebug.profiler_enable=0
xdebug.remote_connect_back=1
xdebug.remote_port=9002
xdebug.remote_autostart=1
xdebug.remote_handler=dbgp

Please note that I don't have a local copy of the code and I don't want to have one. That's the whole point with this setup.

I appreciate any help. Thanks

Upvotes: 1

Views: 2691

Answers (1)

onereal
onereal

Reputation: 147

For me an issue was that xdebug was listening for TCPv6 port but connecting to TCPv4 port. Specifying "hostname":"localhost" made it listen to TCPv4 port

{
   "name": "Listen for Xdebug",
   "type": "php",
   "request": "launch",
   "stopOnEntry": false,
   "hostname": "localhost",
   "port": 9003,
   // server -> local
   "pathMappings": {
     "/var/www/": "${workspaceRoot}/",
   }
},

Upvotes: 1

Related Questions