我将本地开发设置从Linux移植到了一台新的Mac计算机上,并且在让PhpStorm在Mac M1 Pro机器上使用Xdebug时遇到了问题。
我有一个PHP容器,其中安装和配置了Xdebug,如下所示:
zend_extension=/usr/lib/php8/modules/xdebug.so
xdebug.mode=debug
xdebug.idekey=PHPSTORM
xdebug.client_port=9001
xdebug.start_with_request=yes
xdebug.discover_client_host=1
xdebug.log=/var/log/xdebug.log在PhpStorm中,我正在收听端口9001 (其他服务使用9000 )。
下面是在/var/log/xdebug.log的docker容器中的X调试日志
/var/www/html/app # tail -f /var/log/xdebug.log
[49] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[49] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[49] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.18.0.4:9001.
[49] [Step Debug] WARN: Creating socket for '172.18.0.4:9001', poll success, but error: Operation in progress (29).
[49] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: localhost:9001. :-|
[49] [Step Debug] WARN: Creating socket for 'localhost:9001', poll success, but error: Operation in progress (29).
[49] [Step Debug] WARN: Creating socket for 'localhost:9001', connect: Address not available.
[49] [Step Debug] ERR: Could not connect to debugging client. Tried: 172.18.0.4:9001 (from REMOTE_ADDR HTTP header), localhost:9001 (fallback through xdebug.client_host/xdebug.client_port) :-(
[49] Log closed at 2022-03-15 16:28:46.957669我不明白为什么这种联系没有发生/失败。
此外,我还有一个docker-compose.yml文件,该文件具有上面的服务API,如
api:
build:
context: .
expose:
- 8080
container_name: api我已经试过什么了?
success.
docker.for.mac.localhost,然后更改了host.docker.internal,但没有使用host.docker.internal start_with_request=trigger,而没有使用
使用。
更新2022年8月19日-这不能调试cli脚本(phpunit测试)
下面提供的配置答案是通过HTTP请求提供的,但不适用于phpunit测试或cli脚本。
/etc/php8/conf.d/50_xdebug.ini含量
zend_extension=/usr/lib/php8/modules/xdebug.so
xdebug.mode=debug
xdebug.idekey=PHPSTORM
xdebug.client_port=9001
xdebug.start_with_request=yes
xdebug.discover_client_host=0
xdebug.client_host=host.docker.internal
xdebug.log=/var/log/xdebug.log调试不起作用,我得到下面的错误
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 172.18.0.1:9001 (through xdebug.client_host/xdebug.client_port) :-(当我的编辑器PhpStorm试图运行这个
[sshConfig://api-root@docker.dev:2023]:/usr/bin/php -dxdebug.mode=debug -dxdebug.client_port=9001 -dxdebug.client_host=172.18.0.1 /var/www/html/app/vendor/phpunit/phpunit/phpunit --configuration /var/www/html/app/phpunit.xml --filter "/(Tests\\Unit\\App\\Services\\Maps\\GoogleMapsServiceTest::testGetPlaceFromId)( .*)?$/" --test-suffix GoogleMapsServiceTest.php /var/www/html/app/tests/unit/app/Services/Maps --teamcity以及码头机器中的/var/log/xdecg.log日志。
[326] [Step Debug] INFO: Connecting to configured address/port: 172.18.0.1:9001.
[326] [Step Debug] WARN: Creating socket for '172.18.0.1:9001', poll success, but error: Operation in progress (29).
[326] [Step Debug] ERR: Could not connect to debugging client. Tried: 172.18.0.1:9001 (through xdebug.client_host/xdebug.client_port) :-(
[326] Log closed at 2022-08-19 16:24:59.855397我通过修改phpunit解释器配置,以一种黑客的方式修复了这个问题。我不知道为什么在本例中忽略了设置为内部docker主机的/etc/php8/conf.d/50_xdebug.ini值。

发布于 2022-08-19 16:39:41
在调试模式下运行phpunit (或任何cli脚本)的解决方案
正在运行容器的码头内的配置
/etc/php8/conf.d/50_xdebug.ini需要如下所示
zend_extension=/usr/lib/php8/modules/xdebug.so
xdebug.mode=debug
xdebug.idekey=PHPSTORM
xdebug.client_port=9001
xdebug.start_with_request=yes
xdebug.discover_client_host=0
xdebug.client_host=host.docker.internal
xdebug.log=/var/log/xdebug.log但这还不够。
必须手动设置解释器中的配置选项。
xdebug.client_host
在host.docker.internal解释器配置中等于PhpStorm

在cli模式下,这在某种程度上被忽略了,也没有从配置文件/etc/php8/conf.d/50_xdebug.ini中读取,而且当web请求正常工作时,我遇到了测试问题,调试不起作用。
发布于 2022-03-15 16:42:36
xdebug.discover_client_host=1当然不适合与Docker一起使用,您需要将其设置为0。discover_client_host使用headers来查看请求的来源,但是随着NAT与Docker (和PHP)有关,它将看到一个无法连接到的IP地址或主机名。
在Docker中设置xdebug.client_host=host.docker.internal应该是正确的,这应该是网络网关地址,这也是您的主机。
(即使xdebug.discover_client_host=1__,如果它不能连接到它发现的与header发现的不正确的xdebug.client_host设置,Xdebug也会退回到xdebug.client_host设置。)
如果您想查看更详细的日志,还可以添加xdebug.log_level=10,这将提供更多的洞察力。
对于docker-compose.yaml,您不需要在中使用“绑定端口”,因为Xdebug使连接与连接,因此不需要为接收连接而公开端口。
https://stackoverflow.com/questions/71485705
复制相似问题