3
votes

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. :-)

1
Please share your PhpStorm settings. Right now it could be that you created "debug server" entry in PhpStorm for IP address only -- check it at Settings/Preferences | Languages & Frameworks | PHP | Servers. if it's all good there -- collect xdebug related logs (from both IDE and xdebug sides). - LazyOne
(for reference purposes) The same on PhpStorm forums -- intellij-support.jetbrains.com/hc/en-us/community/posts/… - LazyOne
Thanks @LazyOne, I did tried to change Server settings, although they are created automatically when PHPStorm detects a connection (when connecting through external IP). - Ofiris
Updated the question, @LazyOne, following the xdeubg logs, I can see changing 'xdebug.remote_connect_back' to 0 does make PHPStorm and xdebug to work together with localhost - Ofiris
Since it works now -- post your solution with explanation as an answer -- will be useful for other users in similar situation (answered posts will be easier to find .. plus it's an indication that post contain useful info) - LazyOne

1 Answers

10
votes

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.