Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ, PhpStorm: Debugging with xdebug ignores XDEBUG_SESSION cookie

I am trying to debug a Drupal website with the PHP plugin in Intellij (would be the same in PhpStorm).

I have the following setup:

Chrome Browser pointing to a localhost alias mydomain.local and the XDebug Helper extension is installed and set to Debug. In the Developer Tools under Cookies I can see that the XDEBUG_SESSION cookie is set to PHPSTORM.

I have configured php with the xdebug plugin using the following settings:

xdebug.extended_info = 1
xdebug.idekey = "PHPSTORM"
xdebug.max_nesting_level = 500
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = 127.0.0.1
xdebug.remote_mode = req
xdebug.remote_port = 9000

In IntelliJ I have setup a Server pointing to mydomain.local and in the run configuration I am using that server and have set the Ide Key to PHPSTORM.

Now the issue is this:

If I enable Break at first line in PHP scripts, then the debugger immediately breaks at the first breakable location inside the index.php. If I disable that option, I get a warning that no breakpoint was hit, even though I have a break point set and I am certain that the code is being executed. The warning that I see looks like this:

Debug session was finished without being paused
It may be caused by path mappings misconfiguration or not synchronized
local and remote projects.
To figure out the problem check path mappings configuration for 
'mydomain.local' server at PHP|Servers or enable Break at first line in
PHP scripts option (from Run menu).

Now if I explicitly use a URL with the following query parameter appended: ?XDEBUG_SESSION_START=PHPSTORM then all my breakpoints are properly being breaked in IntelliJ.

Question: Why is the XDEBUG_SESSION cookie being ignored?

Update: Added my PHP and XDebug version output from php -v:

PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016,
    by Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

and my Apache virtual host configuration:

<VirtualHost *:80>
    DocumentRoot /var/www/html/mydomain
    ServerName mydomain.local
    <Directory /var/www/html/mydomain>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/mydomain.log
</VirtualHost>

Update 2: I have a php extension installed that is called fpm. I am not quite sure why its installed or if I need it. I think it was automatically installed with php. Could this be interfering?

like image 258
lanoxx Avatar asked Oct 29 '16 20:10

lanoxx


People also ask

How do I know if Xdebug is working?

Verify that Xdebug is properly running by checking again with phpinfo() or php -v as explained above. Note that 9003 is the default port. If this port is used by another service on your system, change it to an unused port. After adding these settings, restart your webserver again.

How do I debug Xdebug?

Press F5 to start the debugger. Click the new XDebug Helper extension and click the Debug option. Finally, refresh the page in the browser to let VSCode react and start the debugging process.


2 Answers

I used to have this issue when I've "overconfigured" my setup.

  1. You might want to try adding the XDebug helper extension to chrome
  2. After adding that go to the plugin's settings and select PhpStorm:

XDebug Helper Settings

  1. Try striping down your xdebug config to these values only:

(works on my box)

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_port=9000
  1. The PhpStorm config should contain debug port 9000 and [X] Can accept external connections:

PhpStorm Xdebug Settings

  1. Then you should have listening to debug connections in PhpStorm on:

PhpStorm Debug Listening

  1. Also enable debugging in your browser (via the xdebug helper):

Xdebug helper Debug

  1. If the bug icon is green xdebug helper debugging on, then if you refresh the page, you should be good to go, and PhpStorm should stop at the first breakpoint.
like image 98
Attila Fulop Avatar answered Sep 28 '22 13:09

Attila Fulop


I had the same problem in PHPStorm 9 while debugging code inside a virtual machine. But first you questions:

Question: Why is the XDEBUG_SESSION cookie being ignored?

Answer: I don't know exactly but I suspect based on that it works when you explicitly specify ?XDEBUG_SESSION_START=PHPSTORM or "break on first line", it is ignoring the incoming request. It will do it's work but don't stop on break points because it thinks it's not needed for the current request.

My solution

What helped me was adding the remote host name/ip to the xdebug, when debugging for browser call. Or export those setting when debugging from command line.

for xdebug.ini

xdebug.remote_host=mydomain.local;
xdebug.remote_connect_back = On

for command line usage:

export PHP_IDE_CONFIG=serverName=mydomain.local; php -dxdebug.remote_autostart=1 -dxdebug.remote_connect_back=1 -dxdebug.remote_host=mydomain.local ./script.php

Then setting up path mapping . To do this go to Settings -> Languages & Frameworks -> PHP -> Server. In there select the server you set up e.g. mydomain.local if existing and enter mydomain.local as host name, with port 80 and XDEBUG. Now check the "Use path mappings" and scroll down to your index.php or some other uniqe entry point you can reach from the browser. The next one sounds stupid but worked for me. If your index.php is located under /home/lanoxx/project/index.php enter the same location under "Absolute path on the server". Then set a breakboint in the index.php file and load page from browser.

like image 40
cb0 Avatar answered Sep 28 '22 13:09

cb0