PHPStorm+Xdebug hits a breakpoint only when using external IP address Follow
Answered
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).
Please sign in to leave a comment.
I don't have any insight into this except to say it works fine for me on Windows 10 using 127.0.0.1/index.php in place of localhost:80/index.php although I usually set up virtual hosts for projects. You may have already tried it but just thought I would mention it.
Hello,
What is your xdebug.remote_host value in php.ini of a local web server?
[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
I also tried 127.0.0.1 and localhost, no help, I think Xdebug does send the debug data correctly
Please try removing the xdebug.remote_connect_back parameter, set xdebug.remote_host to "127.0.0.1", restart Apache and try again.
If it doesn't help, please enable xdebug.remote_log (it's better to create the file and set permissions to 666 manually), try to start a debug session again and show us the resulting log.
Setting
xdebug.remote_connect_back
to 0 (the default value) solved the issue.Xdebug documentation:
When Xdebug tried to connect to localhost, it used TCPv6, which PhpStorm doesn't support. Changing
remote_connect_back
to 0 caused Xdebug to use theremote_host
value, using TCPv4, which PHPStorm supports.http://stackoverflow.com/questions/41423139/phpstormxdebug-hits-a-breakpoint-only-when-using-external-ip-address/41446385#41446385
could you paste your full php.ini section please. trying to get this same setup on my machine and also running into this issue.
Are you using a domain name mapped in /etc/hosts on your local machine? does that make any difference? I can debug mysite.com when using the ipaddress assigned by the router, but cant when using 127.0.0.1
mine:
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.idekey=PHPSTORM
xdebug.remote_host=127.0.0.1
michael ussher,
There's a chance that port 9000 for localhost is occupied by php-fpm (quite a common issue for OS X).
Please shutdown PhpStorm and try to telnet to localhost:9000. Is the attempt successful?
The result is:
--
michaels-MacBook-Pro:~ michael$ telnet localhost:9000
localhost:9000: nodename nor servname provided, or not know
--
edit:
Looks like you're right about php-fpm
michaels-MacBook-Pro:~ michael$ lsof -i :9000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 491 michael 6u IPv4 0x843e5ef17d7a3749 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 552 michael 0u IPv4 0x843e5ef17d7a3749 0t0 TCP localhost:cslistener (LISTEN)
php-fpm 554 michael 0u IPv4 0x843e5ef17d7a3749 0t0 TCP localhost:cslistener (LISTEN)
Fantastic! Thanks Eugene Morozov .
In php.ini I've changed the port to 9001 and in phpstorm -> preferences -> languages and frameworks -> php -> xdebug set that port to 9001 too and restart apache.
Local debugging works. Now I can debug in locations without a router. Happy :)