Asked  6 Months ago    Answers:  5   Viewed   66 times

I'm struggling to get PhpStorm and Xdebug to play nicely on a specific Vagrant VM.

How can I effectively track down and resolve the issue in connecting PhpStorm and Xdebug for this VM?

While I can see that PhpStorm and Xdebug are communicating to a degree, the connection from Xdebug does not launch PhpStorm's debug window, and it's not possible to use PhpStorm's debugging capabilities.

The combination of tools in question is:

  • Vagrant VM with Ubuntu 16-04
  • PHP 7.1 with php-xdebug 2.7
  • PhpStorm 2018.2.1
  • Firefox Xdebug Helper extension
  • Drupal 8.6.10
  • Breakpoint is inserted in index.php at line 16.

I'm able to get this Vagrant VM to connect to Atom's php-debug Xdebug integration. I'm also able to get this PhpStorm to connect to other Vagrant instance's Xdebug!

Xdebug config from the server in question:

# xdebug.idekey = "PHPSTORM"
# xdebug.remote_connect_back = on
xdebug.remote_autostart = off
# xdebug.remote_connect_back = on
xdebug.remote_enable = on
xdebug.remote_handler=dbgp
xdebug.remote_host = 10.0.2.2 # IP of the host system
xdebug.remote_log="/tmp/xdebug.log"
xdebug.remote_mode=req
xdebug.remote_port=9000

I see output in the logfile /tmp/xdebug.log when using this configuration.

  • With Xdebug Helper to "Disable", the page loads in the browser. No log entries are recorded to /tmp/xdebug.log.
  • With PhpStorm set to "Stop listening for PHP Debug connections", the page loads in the browser. No log entries are recorded to /tmp/xdebug.log.
  • With Xdebug Helper set to "Debug" and PhpStorm set to "Start listening for PHP debug connections", the page is paused as though the breakpoint is recognised. However, PhpStorm does not bring up a debug window, so it's not possible to debug. The following is logged to /tmp/xdebug.log:
[8264] Log opened at 2019-03-14 01:39:02
[8264] I: Connecting to configured address/port: 10.0.2.2:9000.
[8264] I: Connected to client. :-)
[8264] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/drupal/web/index.php" language="PHP" xdebug:language_version="7.1.26-1+ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="8264" idekey="PHPSTORM"><engine version="2.7.0"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright></init>
[8264]
[8264] <- feature_set -i 1 -n show_hidden -v 1
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="show_hidden" success="1"></response>
[8264]
[8264] <- feature_set -i 2 -n max_depth -v 1
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_depth" success="1"></response>
[8264]
[8264] <- feature_set -i 3 -n max_children -v 100
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="max_children" success="1"></response>
[8264]
[8264] <- feature_set -i 4 -n extended_properties -v 1
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" feature="extended_properties" success="1"></response>
[8264]
[8264] <- feature_set -i 5 -n notify_ok -v 1
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="5" feature="notify_ok" success="1"></response>
[8264]
[8264] <- stdout -i 6 -c 1
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stdout" transaction_id="6" success="1"></response>
[8264]
[8264] <- status -i 7
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="status" transaction_id="7" status="starting" reason="ok"></response>
[8264]
[8264] <- step_into -i 8
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="8" status="break" reason="ok"><xdebug:message filename="file:///var/www/html/drupal/web/index.php" lineno="14"></xdebug:message></response>
[8264]
[8264] <- eval -i 9 -- aXNzZXQoJF9TRVJWRVJbJ1BIUF9JREVfQ09ORklHJ10p
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="9"><property type="bool"><![CDATA[0]]></property></response>
[8264]
[8264] <- eval -i 10 -- aXNzZXQoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="10"><property type="bool"><![CDATA[1]]></property></response>
[8264]
[8264] <- eval -i 11 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="11"><property type="string" size="9" encoding="base64"><![CDATA[bG9jYWxob3N0]]></property></response>
[8264]
[8264] <- eval -i 12 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9QT1JUJ10p
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="12"><property type="string" size="4" encoding="base64"><![CDATA[ODAwMA==]]></property></response>
[8264]
[8264] <- eval -i 13 -- KHN0cmluZykoJF9TRVJWRVJbJ1JFUVVFU1RfVVJJJ10p
[8264] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="13"><property type="string" size="1" encoding="base64"><![CDATA[Lw==]]></property></response>
[8264]

If I then click "Stop listening for PHP debug connections", I immediately see the following logged to /tmp/xdebug.log:

[8264] <- run -i 14

Then that's quickly followed by this logged output (too large for this question), and the page and resources load as per before.

How can I effectively track down and resolve the issue in connecting PhpStorm and Xdebug for this VM?

PhpStorm > Languages > PHP:

PhpStorm > Languages > PHP

PhpStorm > Languages > PHP > Debug: PhpStorm > Languages > PHP > Debug

 Answers

59

You are using PhpStorm 2018.2.x with Xdebug 2.7.

Either upgrade PhpStorm to the latest stable 2018.3.x or downgrade Xdebug to 2.6.x

The problem is in recently changed XML namespace in Xdebug protocol, as of Xdebug 2.7 (https instead of http). It's fixed/supported since PhpStorm 2018.3.0 (see WI-43622).

Tuesday, June 15, 2021
 
Yrtymd
answered 6 Months ago
57

To answer your confusion directly, two settings stand out. They are xdebug.remote_host and xdebug.remote_connect_back. The former setting's IP is incorrect, especially in a Vagrant setup. It should be something like 10.0.2.2. Furthermore, the latter setting should not be defined and enabled. When it is enabled, it completely ignores the former setting, thus rendering it useless. To summarize, the former setting is wrong, and the latter setting ignores it, but that latter setting is also wrong. These settings are only part of the reason Xdebug will not work, though.

Extended: setup Xdebug in PhpStorm with Vagrant

Vagrant introduces a layer of complexity not present in a standard, non-virtualized development environment. While the points above are probably correct, there are still additional settings and procedures that need to be followed in order to run Xdebug in PhpStorm through Vagrant. I struggled with this for a while, and after several failed attempts, succeeded in getting a connection. There is also a big deficit in documentation available online to achieve this kind of setup, so after successfully getting the whole setup working, I documented the guidelines on my blog. The entire setup process is described in detail, peppered with relevant screenshots. I also use CentOS 6.5 64bit, and the guidelines reflect that. It has even been tested against Magento.

How to configure Xdebug in PhpStorm through Vagrant

Wednesday, March 31, 2021
 
binoculars
answered 9 Months ago
74

I had the exact same error in PhpStorm as the OP.

This answer to a different question solved the problem for me, but I would like to add more detail in my own answer.

The main issue was improperly loaded xdebug. The server mapping issues mentioned in other answers was not an issue for me.

If you load your phpinfo() page and find the xdebug section, and you see this:

XDEBUG NOT LOADED AS ZEND EXTENSION

XDEBUG NOT LOADED AS ZEND EXTENSION

Then you have to fix that before you try anything else! But sometimes this can take some work to track down, if you have multiple php.ini files.

Also in your phpinfo() page, search for "php.ini", (it should be right near the top) and see your "Configuration File (php.ini) Path", and your "Loaded Configuration File". Those are where your xdebug may be loading.

enter image description here

In my case, I correctly loaded it as a Zend extension in my main configuration file in /usr/local/lib/php.ini, like so:

zend_extension = "/usr/local/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"

But in my Loaded Configuration file in /home/someuser/public_html/php.ini, I had it incorrectly loaded like this:

extension=xdebug.so

After fixing that, remote debugging with PhpStorm is working again for me.

As a side note, the first error I saw in PhpStorm was the exact same one the OP mentions, and here is what it looks like:

PhpStorm xdebug server variables error

Cannot accept external Xdebug connection
Cannot evaluate expression 'isset($_SERVER['PHP_IDE_CONFIG'])'

( At first I thought that, because the extension was not loaded properly, PhpStorm was not able to execute PHP code on the server. But now I think PhpStorm only executes php code if you configured an interpreter, which isn't necessary for debugging. For debugging, PhpStorm just needs the xdebug connection and the correct path mappings.)

Later, I found the "Command is not available" error in the xdebug log on my server, which led me to the solution.

Here, by the way, is what I have in my local php.ini for xdebug:

;extension=xdebug.so <- this is the bad line commented!
zend_extension = "/usr/local/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"

xdebug.remote_enable=true
xdebug.remote_port="9000"
xdebug.profiler_enable=1
xdebug.profiler_output_dir="/tmp/xdebug-someuser/"
xdebug.profile_enable_trigger=1
xdebug.trace_enable_trigger=1
xdebug.idekey="PHPSTORM"
xdebug.remote_log="var/log/xdebug/xlog"
Wednesday, July 28, 2021
 
AntoineB
answered 5 Months ago
57

Xdebug 3 will be fully supported in PhpStorm 2020.3 version only, which is currently in EAP stage (Early Access Program) and will be released in about 1 month time.

It is already supported in the most recent EAP #6 build: check this blog post for more info: https://blog.jetbrains.com/phpstorm/2020/11/phpstorm-2020-3-eap-6/


I have downloaded Xdebug 3.0.0beta1 for my PHP 7.4 on Windows 10, configured it from scratch (using correct Xdebug 3 config values: https://3.xdebug.org/docs/upgrade_guide and https://3.xdebug.org/docs/all_settings) ... and it still works fine in PhpStorm 2020.2.3.

Yes, IDE sends old-style parameters when initiating debugging for a CLI script (like xdebug.remote_{host, port} etc) but the debug still works just fine.

This is my php.ini content for Xdebug 3 settings (as simple as this):

[xdebug]
xdebug.client_host = 127.0.0.1
xdebug.client_port = 9001
xdebug.mode = debug

(I have a bit mores settings, but those are customisation for output file names, log locations, extra stuff for quickly turn on some options in some scenarios/when needed etc -- these are not needed here and it works fine without them)
enter image description here

CLI debug initiated from IDE ("PHP Script" type of configuration):
enter image description here

That's what IDE is executing: E:Projectsphpphp74php.exe -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9001 -dxdebug.remote_host=127.0.0.1 E:Projectsweb_idetesttest.php. As you may see these old style parameters do not affect Xdebug 3 at all.

P.S. If I set xdebug.start_with_request = yes in php.ini then debug will work even for Run (or when executing that PHP script outside of IDE) -- as long as "phone handle" icon is green (IDE listens for incoming debug requests).

Friday, August 27, 2021
 
Corbin March
answered 4 Months ago
66

Well I solved it by putting the xdebug settings in /etc/php5/apache2/conf.d/20-xdebug.ini

Wednesday, November 17, 2021
 
treeface
answered 2 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share