简体   繁体   English

Xdebug: 无法连接到调试客户端 (Phpstorm + WSL2)

[英]Xdebug: Could not connect to debugging client (Phpstorm + WSL2)

I am trying to convert my recent XAMPP development setup to a LAMP stack based on WSL2.我正在尝试将我最近的 XAMPP 开发设置转换为基于 WSL2 的 LAMP 堆栈。

So far I've been successful.到目前为止,我已经成功了。 I can access my testpage test.php containing <?php phpinfo();我可以访问我的测试页test.php包含<?php phpinfo(); via https://localhost/test.php (using a self-signed certificate for dev-purposes.)通过https://localhost/test.php (使用自签名证书用于开发目的。)

Sadly, I'm completely stuck at getting Xdebug to work.可悲的是,我完全无法让 Xdebug 正常工作。

Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(

I have been going through these threads already, but to no avail:我已经经历过这些线程,但无济于事:

My setup:我的设置:

  • Windows 10 with WSL2 installed Windows 10 安装了 WSL2
  • Ubuntu 20.04 with Apache2 Ubuntu 20.04 与 Apache2
  • PHP 8.0.5 with Xdebug 3.0.4 PHP 8.0.5 与 Xdebug 3.0.4
  • PhpStorm (IDE) PhpStorm (集成开发环境)

My Xdebug settings at /etc/php/8.0/apache2/php.ini :我在/etc/php/8.0/apache2/php.ini的 Xdebug 设置:

[xdebug]
xdebug.mode=debug
xdebug.remote_port=9003
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.remote_host=localhost
xdebug.idekey=PHPSTORM
xdebug.discover_client_host=1

;xdebug.client_host=localhost
;xdebug.remote_enable=1
;xdebug.remote_handler=dbgp

I have tried commenting "discover_client" and explicitly setting the client host to localhost.我试过评论“discover_client”并将客户端主机明确设置为本地主机。 No change.不用找了。

The output of phpinfo() seems to indicate that these settings are not ignored. phpinfo() 的 output 似乎表明这些设置没有被忽略。 See screenshot of the relevant parts .请参阅相关部分的屏幕截图

The relevant settings for the virtual host in /etc/apache2/sites-available/default-ssl.conf are: /etc/apache2/sites-available/default-ssl.conf中虚拟主机的相关设置为:

<VirtualHost: *:443>
    ServerName localhost
    DocumentRoot "/mnt/d/projects/testproject/public"
    <Directory "/mnt/d/projects/testproject/public/">
        Options +Indexes +Includes +FollowSymlinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

(The "all granted" is only temporary while debugging) (“全部授予”在调试时只是暂时的)

I don't know if this is relevant, but I made sure that C:\Windows\System32\drivers\etc\hosts contains我不知道这是否相关,但我确定C:\Windows\System32\drivers\etc\hosts包含

127.0.0.1 localhost
::1 localhost

So when I run所以当我跑步时

php -dxdebug.mode=debug /mnt/d/projects/testproject/public/test.php

I get我得到

Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(

Does anyone see the problem?有人看到问题了吗? Or can anyone give me a hint on where to look next?或者任何人都可以提示我接下来要看的地方吗?

The option xdebug.start_with_request = yes tells Xdebug to try to debug every single request/script.选项xdebug.start_with_request = yes告诉 Xdebug 尝试调试每个请求/脚本。 If Xdebug fails to connect to the debug client (it takes values from xdebug.client_host and xdebug.client_port , or autodetected host if xdebug.discover_client_host is enabled) then it notifies you about that.如果 Xdebug 无法连接到调试客户端(它从xdebug.client_hostxdebug.client_port获取值,或者如果启用了xdebug.discover_client_host则自动检测主机)然后它会通知你。

Normally such a messages will be written to the standard PHP's error log.通常这样的消息将写入标准 PHP 的错误日志。 Looks like you don't have it configured at all in your php.ini (as this is how it comes by default), therefore PHP sends it to your standard output instead.看起来你根本没有在你的 php.ini 中配置它(因为这是默认情况下的配置),因此 PHP 将它发送到你的标准 output。

If you want to prevent it from appearing on you terminal output you have to point the PHP error_log to a valid location.如果你想阻止它出现在你的终端 output 上,你必须将 PHP error_log 指向一个有效的位置。

Example of how I solved it in my case:在我的案例中我如何解决它的示例:

1- Edit your ini file: 1- 编辑您的 ini 文件:

sudo vi /etc/php/7.4/cli/php.ini

2- And add this line: 2- 并添加这一行:

error_log = /var/www/log/php_error.log

NOTE: Change the previous routes to any valid directory you want.注意:将以前的路由更改为您想要的任何有效目录。

3- Try again and the warning should disappear and now goes to the log file. 3- 再试一次,警告应该消失,现在转到日志文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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