Xdebug Remote Debugging inside Docker on remote server

uziau

I need to debug PHP scripts located inside a Docker container on a remote server.

Usually, I debug my code using Visual Studio Code in Windows. I've been debugging my dev codes (which is located in a Vagrant) this way without any problem.

But when it comes to debugging files in a Docker on a remote server I couldn't get it to work.

Here's my xdebug setting on php.ini (in docker located on a remote server)

xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host=172.18.0.1
xdebug.remote_port=9000
xdebug.remote_log=/tmp/debug.log

The remote_host IP address in the setting above is the IP of the remote host seen from inside Docker.

I've tried ssh-tunneling to my remote server (from Windows, using telnet).

But when I try to run the site on my browser, my Visual Studio Code couldn't detect the debugging session.

Basically what I did are these:

  1. Start a debugging session on my local machine (Windows)
  2. Create ssh-tunnel to remote server (forwarding port 9000 on the server to localhost:9000) using ssh -R 9000:localhost:9000 [email protected]
  3. Mapped port 9000 on Docker to port 9000 on remote server
  4. Xdebug in docker is set to listen to its host (so to IP address of host seen from inside docker, which I got from running this command from inside docker: /sbin/ip route|awk '/default/ { print $3 }'

When I run the site, the /tmp/debug.log contains this:

I: Connecting to configured address/port: 172.18.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///magento/test.php" language="PHP" xdebug:language_version="5.6.33-1+ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="12776" idekey="www-data"><engine version="2.5.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2017 by Derick Rethans]]></copyright></init>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

How can I 'relay' the connection set by Xdebug from Docker, to my remote server, to the IDE on my local pc?

likemusic

I have no success to do the same by ssh-tunnel :(

But it's possible by ngrok. You should:

  1. install ngrok on your local development machine;
  2. run ngrok tcp 9000;
  3. set xdebug.remote_port and xdebug.remote_host according to ngrok's info.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

PhpStorm + Xdebug remote debugging froze

Python remote debugging with docker

Setup Xdebug and PHPStorm with remote server

How can I see the $_POST variable in PhpStorm when debugging a remote server with Xdebug?

VS Code PHP Debugging without xdebug.remote_autostart=1

Can I connect to remote DB server from inside docker container?

Using the Erlang Observer App with a remote Elixir Phoenix server inside Docker

Remote debugging JVM in docker on AWS EB

Python Docker Remote Debugging VS Code

Remote debugging NodeJS in Docker with Visual Studio Code

Node js docker remote debugging chrome

eclipse: remote debugging a tomcat server behind a firewall

PhpStorm and Remote XDebug not working

PhpStorm remote Xdebug

How to reverse SSH tunnel to remote docker container for Xdebug?

How to trigger only my requests using Xdebug on remote server

ECONNREFUSED Inside of Docker Container; Accessing Remote API

Do PHP source files need to exist locally AND remotely when using XDebug remote debugging in eclipse?

Bash variable inside third remote server

How to watch xvfb session that's inside a docker on remote server from my local browser?

Remote debugging Java 9 in a docker container from IntelliJ IDEA

Running/Debugging Pycharm Python Scripts with remote Docker Machine

Executable in docker container does not register breakpoints from gdb remote debugging

Debugging with Docker Compose remote interpreter: db container unknown

Remote debugging problems

Remote debugging path mapping

Debugging Remote Java Application -

Remote debugging - Unverified breakpoint

Remote debugging a Java application