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?
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.
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.
I used to have this issue when I've "overconfigured" my setup.
(works on my box)
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_port=9000
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With