Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you use php xdebug if you are on NAT behind a firewall?

I have the following use case for debugging a PHP application:

  • The developer does have a private IP address
  • The developer can connect only to a limited number of ports from the server, like 80, 8080, 3128, others being limited by the outgoing firewall. Still if the outgoing requests are HTTP he could use a proxy that does not have this limitation.
  • the server machine is fully configurable

Is is possible to use xdebug in this circumstance? How?

It is possible to establish a VPN but this is not an easy solution so I would prefer a simplified one.

like image 645
sorin Avatar asked Sep 25 '10 13:09

sorin


2 Answers

The solution I found was to use PuTTY to forward the port 9000 from the server to the client (IDE).

putty configuration screenshot

Just configure the Xdebug to connect to the localhost instead of an IP address your client (IDE) is running on:

xdebug.remote_host = localhost
xdebug.remote_port = 9000
xdebug.remote_connect_back = 0

There is a nice article called Remote Debugging PHP with a Firewall in the Way describing this and also the Xdebug configuration and SSH port forwarding method.

like image 122
sorin Avatar answered Oct 07 '22 00:10

sorin


Another variant is to use SSH port forwarding (can be used also in Cygwin).

Simply execute:

ssh -R 9000:127.0.0.1:9000 host.example.com

It creates a tunnel which forwards the port 9000 on the remote host to the port 9000 on the localhost.

Everything else is the same as in the PuTTY method (see sorin's answer).

like image 32
OZ_ Avatar answered Oct 07 '22 00:10

OZ_