简体   繁体   中英

Issues connecting Vagrant Xdebug with PhpStorm 2020.3

Have spent over a day trying to get PhpStorm to debug a Drupal site inside a Vagrant virtual machine running Xdebug and I feel I'm close - but just not quite there yet.

Currently, in PhpStorm when debugging I have an error:

Waiting for incoming connection with ide key 'PHPSTORM'

In the Xdebug log in the VM (at /tmp/xdebug.log )

[2094] I: Checking remote connect back address.
[2094] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[2094] I: Checking header 'REMOTE_ADDR'.
[2094] I: Remote address found, connecting to 192.168.88.1:9000.
[2161] E: Time-out connecting to client (Waited: 200 ms). :-(
[2161] Log closed at 2020-12-15 04:25:32

I tried setting up the Zero-configuration debugging without any luck.

For the debugging configuration, I have a PHP Remote Debug that validates correctly although it always defaults to the 'Local Web Server or Shared Folder' rather than the 'Remote Web Server' option.

When I started the project I set it up as a local web server option and I'm worried that I haven't changed the correct settings to now make this a remote web server. The connection type for the deployment is now 'Local or mounted folder' but originally this was 'In-place'.

Under Languages & Frameworks --> PHP --> Servers, I set this up on port 80, using Xdebug and without path mappings. I tried changing the port etc but then it doesn't validate so I'm confident that the server settings are correct and that PhpStorm is talking to the virtual machine correctly.

I changed the /etc/php/7.4/cli/php.ini file but phpinfo() says the configuration is coming from /etc/php/7.4/fpm/php.ini . The changes I made in the php.ini file are active though. phpinfo() is showing:

xdebug.idekey: PHPSTORM
xdebug.remote_host: 10.0.2.2
xdebug.remote_port: 9000
xdebug.remote_autostart: Off
xdebug.remote_connect_back: On

Really at a loss now as to what to try next. It is incredibly frustrating so hope someone can shed some light.

EDIT --- As per comment here is the screenshots of the setup:

部署

Deployment: Local or mounted folder

PHP 设置

PHP settings

服务器详情

The server setup

调试设置

Debug settings

验证调试器

Validate the debugger from the remote server

带有调试插件的 Chrome

Run Chrome with the debug addon running

错误信息

The error message

运行配置设置

The Run debug configuration settings

phpinfo()

Start of the phpinfo with the config file showing where the xdebug settings need to be edited.

Xdebug 设置

The Xdebug settings of phpinfo()


Some of the tests as per the comments:

远程登录测试

After logging in to 'vagrant SSH' it shows the IP address to be used (10.0.2.2). The local computer is also IP 10.1.1.150 a telnet test of both of these works.

Xdebug 配置

A 'sudo nano' of the Xdebug ini file


NOTE: Changing the remote connect back to 0 fixed the connection:

xdebug.remote_connect_back=0

And then the path mapping needed to be turned on in the Server settings and then everything was working correctly.

Big thanks to LazyOne for his helpful and thorough comments. :)

1) Check if there are separate php.ini files used by web server, -- you need to edit the right php.ini file.

Run phpinfo() and check to see if there is an ini file for Xdebug. In my case this was at /etc/php/7.4/fpm/conf.d/20-xdebug.ini

2) What's your Xdebug version?

Version 2 and 3 of Xdebug have slightly different parameters. In my case I was running Xdebug 2.9.5

3) What is the IP address of your Host OS as seen from the inside the VM? That's where Xdebug should connect (as it's Xdebug that connects to IDE and NOT other way around).

When you first log in to the SSH there will be an IP address shown. This is what the IP should be for Xdebug. In my example, this was 10.0.2.2

4) xdebug.remote_connect_back: On -- try set it off and ensure that you have correct xdebug.remote_host (as Xdebug v2 may not fallback to remote_host value when autodetected IP fails.

This fixed my connection!

sudo nano /etc/php/7.4/fpm/conf.d/20-xdebug.ini

Then change:

xdebug.remote_connect_back=1

To:

xdebug.remote_connect_back=0

Save, and then restart the server.

Test the connection again. After this step I had a connection between the host and remote server but I also had to turn on path mapping in PhpStorm to get the debugger working 100%.

5) Ensure that PhpStorm is the one that listens on Xdebug port when "phone handle" icon is enabled (use netstat or alike to confirm) and is allowed in firewall.

6) If you know the correct IP and sure that PhpStorm is listening -- you can just use telnet from inside the VM and try to connect to IDE on Xdebug port -- if connected then IP, port and firewall is most likely set up correctly.

Even with the error messages, the telnet check was working. So it pointed to the issue being with the Xdebug setup rather than the handshaking between the host and remote server.

Thanks to LazyOne's comments for finding the answer and for presenting a great workflow to help identify the problem.

I was experiencing something very similar to what you described. I was able to start a debug session from the xdebug cli tool (dbgpClient) which proved to me that it was an issue with phpStorm.

My project is using a legacy version of xdebug. (2.2.7)

Downgrading to phpStorm 2020.2.4 resolved my issue . (It's one-click in the jetbrains toolbox to downgrade)

Thanks for the answers in this issue. It took me half a day to find out that xdebug 2.2.7 with php5.3.10 doesn't work on Phpstorm 2020.3. So I downgraded to 2020.2.4 and it works again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM