Search code examples
sshphpstormxdebugssh-tunnel

PhpStorm ssh tunnel to remote server - anything to configure on remote server?


I have literally been struggling with this for weeks. I gave up and successfully connected to a local virtual machine, but it is too slow. I have to connect to this remote machine even if it kills me.

I have PhpStorm 9.0.2 on my Windows 8.1 machine, trying to use PuTTY to connect to remote CentOS 6, PHP 5.6 / xdebug 2.3.2 machine at another location. I am behind a firewall, but I don't think that's the issue since I can connect by SSH with no problem, so the tunnel should work if I can just configure it correctly. I think the only issue is I am too dumb to figure out how to tunnel properly.

How does the remote server's xdebug know to tunnel? Or does it need to know? Do I need to tell that server about the tunnel? Or is it already aware of it as soon as I connect via the tunnel? But if is aware, then why can't xdebug connect on port 9000? Does my PhpStorm listen on port 9000, and my PuTTY handle sending the data there? Or does PhpStorm need to listen on port 22?

This tutorial I found that explains how to use PhpStorm with a remote server by SSH tunnel does not work (click to expand the section "Setting up an SSH tunnel on Windows). Xdebug on my remote testing server, the CentOS Linux machine where my PHP/MySQL based development website is sitting, cannot connect to my local Windows 8.1 development machine on port 9000.

I don't fully understand tunneling, and maybe I never will, as I have spent several hours researching it and have yet to grasp it. I just want to debug my application. :(

The tutorial instructs you to use Putty to open up an SSH connection to your remote server and configure the "tunnels" section of the connection to specify port 9000 on the remote host, and localhost:9000 for your local development machine. I have done that, over and over again, but it seems that no one told my remote server what to do.

Here are my putty settings:

PuTTY configuration 1 (fake ip address) PuTTY configuration 2 - the TUNNEL

The XDebug log keeps on showing that it failed to connect.

I: Checking remote connect back address.
I: Remote address found, connecting to 173.12.34.123:9000.
E: Time-out connecting to client. :-(
Log closed at 2015-10-28 19:31:55

How can I tell if my remote XDebug is trying a direct connection to my server on port 9000, or if it is using the tunnel through port 22?

Does it matter which user I connect as through SSH? root or some other user? Does it matter if I have another SSH session connected to the same server at the same time that is not tunneled?

EDIT: Here are my xdebug settings as outputted by phpinfo(). They reflect the php.ini from my current website's root (/home/testingsite/public_html/php.ini). Note that the xdebug.remote_log is being saved in /home/testingsite/public_html/var/xdebug/log.txt

xdebug

xdebug support  enabled
Version 2.3.2
IDE Key PHPSTORM

Supported protocols Revision
DBGp - Common DeBuGger Protocol $Revision: 1.145 $

Directive   Local Value Master Value
xdebug.auto_trace   Off Off
xdebug.cli_color    0   0
xdebug.collect_assignments  Off Off
xdebug.collect_includes On  On
xdebug.collect_params   0   0
xdebug.collect_return   Off Off
xdebug.collect_vars Off Off
xdebug.coverage_enable  On  On
xdebug.default_enable   On  On
xdebug.dump.COOKIE  no value    no value
xdebug.dump.ENV no value    no value
xdebug.dump.FILES   no value    no value
xdebug.dump.GET no value    no value
xdebug.dump.POST    no value    no value
xdebug.dump.REQUEST no value    no value
xdebug.dump.SERVER  no value    no value
xdebug.dump.SESSION no value    no value
xdebug.dump_globals On  On
xdebug.dump_once    On  On
xdebug.dump_undefined   Off Off
xdebug.extended_info    On  On
xdebug.file_link_format no value    no value
xdebug.force_display_errors Off Off
xdebug.force_error_reporting    0   0
xdebug.halt_level   0   0
xdebug.idekey   PHPSTORM    PHPSTORM
xdebug.max_nesting_level    256 256
xdebug.max_stack_frames -1  -1
xdebug.overload_var_dump    On  On
xdebug.profiler_aggregate   Off Off
xdebug.profiler_append  Off Off
xdebug.profiler_enable  On  On
xdebug.profiler_enable_trigger  On  On
xdebug.profiler_enable_trigger_value    no value    no value
xdebug.profiler_output_dir  var/xdebug/profiles/    var/xdebug/profiles/
xdebug.profiler_output_name cachegrind.out.%p   cachegrind.out.%p
xdebug.remote_autostart Off Off
xdebug.remote_connect_back  On  On
xdebug.remote_cookie_expire_time    3600    3600
xdebug.remote_enable    On  On
xdebug.remote_handler   dbgp    dbgp
xdebug.remote_host  localhost   localhost
xdebug.remote_log   var/xdebug/log.txt  var/xdebug/log.txt
xdebug.remote_mode  req req
xdebug.remote_port  9000    9000
xdebug.scream   Off Off
xdebug.show_exception_trace Off Off
xdebug.show_local_vars  On  On
xdebug.show_mem_delta   Off Off
xdebug.trace_enable_trigger Off Off
xdebug.trace_enable_trigger_value   no value    no value
xdebug.trace_format 0   0
xdebug.trace_options    0   0
xdebug.trace_output_dir /tmp    /tmp
xdebug.trace_output_name    trace.%c    trace.%c
xdebug.var_display_max_children 128 128
xdebug.var_display_max_data 512 512
xdebug.var_display_max_depth    3   3

Solution

  • Accordingly to your xdebug log you have an error in settings there rather than in SSH.

    Based on your xdebug section of phpinfo() out put you need to set xdebug.remote_connect_back = 0 (or off -- same meaning). Also make sure that xdebug.remote_host = localhost.

    With your current settings xdebug tries to connect back to the TCP 9000 on IP where request came from while for SSH tunnelling to work you need it to connect to local TCP 9000 (and SSH will tunnel such connection back to your local machine bypassing firewall/router).