Search code examples
phpstormxdebug

PhpStorm+Xdebug hits a breakpoint only when using external IP address


Using MacOS Sierra, PhpStorm and Xdebug, web application configured on port 80 (not running from PhpStorm).

When browsing to localhost:80/index.php, PhpStorm won't stop on breakpoint, when accessing the external IP 192.168.1.2/index.php, PhpStorm hits the breakpoint.

I would like to use localhost for debugging instead of the external IP.

Is there a way to make PhpStorm to work with localhost?

P.S. Visual Studio Code works in both scenarios (therefore I believe Xdebug and PhpStorm are working good).

[xdebug]
zend_extension = /usr/local/Cellar/php56/5.6.29_5/lib/php/extensions/debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.idekey=vagrant
xdebug.remote_host=0.0.0.0

Tried to set xdebug.remote_host to 127.0.0.1 and localhost, same behavior.

When debugging localhost:80, xdebug log show:

Log opened at 2017-01-03 14:06:36
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to ::1:9000.
W: Creating socket for '::1:9000', poll success, but error: Operation now in progress (19).
E: Could not connect to client. :-(
Log closed at 2017-01-03 14:06:36

When using VS Code, there is no error and xdebug shows instead I: Connected to client. :-)


Solution

  • Setting xdebug.remote_connect_back to 0 (the default value) solved the issue.

    Xdebug documentation:

    If enabled, the xdebug.remote_host setting is ignored and Xdebug will try to connect to the client that made the HTTP request. It checks the $_SERVER['HTTP_X_FORWARDED_FOR'] and $_SERVER['REMOTE_ADDR'] variables to find out which IP address to use.

    When Xdebug tried to connect to localhost, it used TCPv6, which PhpStorm doesn't support. Changing remote_connect_backto 0 caused Xdebug to use the remote_host value, using TCPv4, which PhpStorm supports.