Vscode-php-debug: Debugging with Remote SSH

Created on 9 Jun 2019  路  10Comments  路  Source: xdebug/vscode-php-debug

I've been successfully using PHP Debug with a remote host in a normal project. However I've just setup the new Remote - SSH extension and am trying to get PHP Debug to work with that. Is this possible? What do I need to do?

Most helpful comment

Okay, so I got this to work by configuring xdebug with xdebug.remote_host=127.0.0.1 and disabling xdebug.remote_connect_back.

All 10 comments

Okay, so I got this to work by configuring xdebug with xdebug.remote_host=127.0.0.1 and disabling xdebug.remote_connect_back.

Yes, the dbgp code runs on the remote server, while http requests come from your browser... Would be a nice use-case for dbgp proxy...

I cannot get this to work either. Oddly enough, if I use an undefined constant then the debugger works and pauses on the exception. However, adding a breakpoint has no effect whatsoever. The code will not halt on the breakpoint. Any ideas?

That would point to invalid path mapping. Check if you have anything under pathMappings in your config. Or something else wrong with paths. Do you use docker or similar? You can also set stopOnEntry and log in your config, to help debug this.

I have the following folder open in my workspace "\~/public_html/mlinks" and that is the document root for the web application. My pathMapping thus contains "\~/public_html/mlinks/": "${workspaceFolder}". I did try expanding out the tilde to the actual path but that didn't change. I feel that my understanding of pathMappings might be inaccurate.

If you are using VSCode Remote SSH that means that the debugger client is running on the same box as the web server. You should not need the pathMapping, try to remove it.

Okay, so I got this to work by configuring xdebug with xdebug.remote_host=127.0.0.1 and disabling xdebug.remote_connect_back.

Hi,

I have tried this configuration & it works. Problem is now it doesn't work with local configuration.

Do we have some setting / configuration which will work in all scnerio?

I tried several scenario where used SSH-FS but it needs files in local PC to debug. Help will be highly appreciated.
Following works for remote debugging:

zend_extension=/usr/lib/php/20190902/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_port = 9001
xdebug.remote_host = 127.0.0.1
xdebug.max_nesting_level = 512
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1
xdebug.remote_log = /tmp/rxdebug.log

Following Works for Debugging when I have files in Local Folder & Uploading them via SCP:

zend_extension=/usr/lib/php/20190902/xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9001
xdebug.max_nesting_level = 512
xdebug.remote_handler=dbgp
xdebug.remote_autostart=1
xdebug.remote_log = /tmp/rxdebug.log

Hi. Mixing these two scenarios is problematic. In theory there are two ways to do this:

  1. use a dbgpproxy, where the proxy runs on the server, next to php, and php uses xdebug.remote_host=127.0.0.1 but this plugin lacks proxy support (there's an open PR, but doesn't go anywhere)
  2. Leave the xdebug.remote_connect_back=true and use the SSH tunnel feature of VSCode remote to actually connect to PHP through the tunnel, so that PHP (webserver) will see connections comming from 127.0.0.1. This would however require manipulating your workstation PCs /etc/hosts (or some other way) to trick your browser to connect to your VSCode clients endpoint of the SSH tunnel.

My question is if we enable to provide SCP path to pathMappings settings in your launch.json it can solve this scenario.
"pathMappings": {
"/var/www/html": "${workspaceRoot}/www"
}

==> Here if we could point SCP Mounted file system path

I "solved" it adding this to the apache configuration:

     RewriteEngine On
     RewriteCond %{QUERY_STRING} ^(?:.*&)?localdebug=true.*$
     RewriteRule ^ - [E=DEBUG_HOST:localhost]

Then in the xdebug.ini I set the following:
xdebug.remote_addr_header="DEBUG_HOST"

Then when I add to the url ?localdebug=true it will use localhost.
But I'm still searching for a better solution than this.

Edit: Thanks for the tip for using port forwarding. When debug session is started I just forward Port 9000 in the Remote Explorer plugin and everything is working.

Was this page helpful?
0 / 5 - 0 ratings