Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode remote debugging with Xdebug when using SSH connection to edit code

Not sure how to configure the pathMappings in the VSCode debug config when I open a remote directory on a Linux webserver from a Windows machine using the VSCode Remote Explorer SSH plugin. If I store a copy of source locally and initiate VSCode with local source the debugging works fine.

Web server is Ubuntu 14 Lamp, local system is Windows 10. Using Remote Explorer plugins in VSCode to ssh into Linux server from Windows workstation and edit source on server.

This works fine in VSCode debug config when I have source files stored locally and initiate VSCode by opening my local copies.

        pathMappings": {
           "/var/www/html/codeigniter/": "${workspaceRoot}",
        },

When I initiate VSCode on Windows by using the Remote Explorer, this config does not work. I connect via remote explorer to this root folder /var/www/html/codeigniter/

I expect to have the breakpoints recognized and stop the code when I open the files on the Linux server via the SSH plugin for VSCode, but they are not and the code runs without hitting breakpoints.

like image 516
user2714083 Avatar asked Dec 22 '22 21:12

user2714083


1 Answers

Thanks for the reply. I wanted to avoid having a copy of my code so I can edit as I debug. I did end up getting things working. So I can use the VSCODE ssh connect and then debug and edit source on the server without making a local copy.

"name": "Listen for XDebug",
"type": "php",
"request": "launch", 
"port": 9000    

on my linux server my xdebug settings

xdebug.remote_handler=dbgp
xdebug.remote_log="/tmp/xdebug/log"
xdebug.profiler_enable = 1
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_autostart = 1
xdebug.remote_host = 127.0.0.1

I had to set remote_host to the localhost, then everything worked. I didn't understand xdebug enough to realize that remote_host would need to be set even if the IDE debugger is running on the same host . I also didn't understand enough about vscode to realize when in SSH remote edit mode, the debug component is actually installed on the remote server making it a localhost connection between xdebug and remote host.

anyway, issue resolved. Thanks for the answers, that helped me on my path.

like image 113
user2714083 Avatar answered Mar 19 '23 06:03

user2714083