Search code examples
linuxphpstormxdebugvhosts

Is it possible to forward Xdebug connections?


I want to setup a kind of debug tunnel.

Setup:

  1. Remote webserver running on a Linux VM
  2. Two vhosts (H1, H2) on this machine
  3. Both hosts have Symfony 4 running as WebApi
  4. I use PhpStorm locally on Windows 10 as IDE
  5. H1 is an API
  6. H2 as well
  7. Both want to communicate via cURL

If I make a Postman request to H1 or H2 Xdebug works great.

Now I want to send a cURL request from H1 to H2 and want to debug the request on H2 locally in PhpStorm.

As far as I understand, Xdebug will connect back to H1 because the request came from there.

What I want, is that it connects back to me, locally, instead of to H1 remotely.

Is this possible with my described setup?:

CLI Command on H1 -> cURL Request to H2 -> Xdebug locally in PhpStorm

Both vhosts use php7.2 and the same php.ini

Thank you all very much in advance


Solution

  • Thank you @lazyone.

    For me the right answer was to disable the connect_back Option.

    Here the config

    [xdebug]
    zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so"
    xdebug.remote_autostart = 1
    xdebug.remote_enable = 1
    xdebug.remote_port = 9000
    xdebug.remote_host = 192.168.56.1
    xdebug.show_local_vars = 1
    

    Your last comment helped me to understand it.

    I didn’t know that xdebug always tries to connect to the remote ip, no matter where the request came from.

    Remote in this case means: remote from the servers view and this is my local client.

    It works now. Thank you very much.