Search code examples
phpstormxdebug

Xdebug ignores breakpoints (browser and CLI)


I've been trying to setup Xdebug on PHP 7.2 with nginx (or cli) with no avail so far. The breakpoints are simply ignored. Tried activating them with PhpStorm and manually using xdebug_break().

All of the methods are at least triggering Xdebug, as error logs say (you can see the code in question in the picture below), but nothing happens:

Log opened at 2018-04-21 07:50:31
I: Connecting to configured address/port: 127.0.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///Users/riseandcry/Projects/php/jobApplication/index.php" language="PHP" xdebug:language_version="7.2.2" protocol_version="1.0" appid="9859" idekey="PHPSTORM"><engine version="2.6.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2018 by Derick Rethans]]></copyright></init>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="break" reason="ok"><xdebug:message filename="file:///Users/riseandcry/Projects/php/jobApplication/index.php" lineno="4"></xdebug:message></response>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" status="stopping" reason="ok"></response>

Log closed at 2018-04-21 07:50:31

my config is this:

zend_extension=/usr/local/Cellar/php72/7.2.2_13/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_connect_back=0
xdebug.idekey="PHPSTORM"
xdebug.remote_log=/Users/riseandcry/Projects/php/xdebug/xdebug.log
xdebug.extended_info=1
xdebug.force_display_errors=1

I don't have any other extensions loaded in PHP, and PhpStorm validation shows that everything is correct:

enter image description here

Also, I already reinstalled everything (PHP, nginx, Xdebug), with various methods and it still does not work. My guess is that it's either Xdebug or config at fault, but no idea what.

Would really appreciate some help. I also read pretty much all of the related questions on SO and other forums and since I'm here, you can guess the outcome...


Solution

  • You are on Mac and you are using nginx... This means that most likely you do have php-fpm installed and running. Problem is that php-fpm also uses TCP 9000 port by default ... so right now Xdebug is connecting there instead of PhpStorm (the xdebug log gives a good hint here, if you have seen such response before).

    Unfortunately PhpStorm is unable (for whatever reason) to detect that Xdebug port is already used by another app on Mac (but does it fine on Windows/Linux).

    You can verify that manually with this sort of command (look for the entry that uses Xdebug port and see the process name):

    sudo lsof -nP -iTCP -sTCP:LISTEN
    

    The solution is to change Xdebug port to be 9001 (or any other meaningful number) in both php.ini and PhpStorm settings.

    P.S. You will need to restart all debug sessions / disable and enable "phone handle" icon if you are using it. Alternatively just restart the IDE.