【发布时间】:2021-08-30 13:40:37
【问题描述】:
我使用 Docker 搭建了一个 Laravel 开发环境 - nginx:stable-alpine、php:8.0-fpm-alpine 和 mysql:5.7.32。我从我的 php.dockerfile 安装 Xdebug:
RUN apk --no-cache add pcre-dev ${PHPIZE_DEPS} \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& apk del pcre-dev ${PHPIZE_DEPS}
并在 docker-compose 中包含两个卷以将 php 指向 xdebug.ini 和 error_reporting.ini:
volumes:
- .:/var/www/html
- ../docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ../docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
我的 xdebug.ini 看起来像这样:
zend_extension=xdebug
[xdebug]
xdebug.mode=develop,debug,trace,profile,coverage
xdebug.start_with_request = yes
xdebug.discover_client_host = 0
xdebug.remote_connect_back = 1
xdebug.client_port = 9003
xdebug.remote_host='host.docker.internal'
xdebug.idekey=VSCODE
当我返回 phpinfo() 时,我可以看到一切设置正确,显示已安装 xdebug 版本 3.0.4,但是当我在 VSCode 中设置断点并运行调试器时,它没有命中它。
我的 launch.json 如下所示:
{
"version": "0.2.0",
"configurations": [
{
"name": "XDebug Docker",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceFolder}/src",
}
},
]
}
我的文件夹结构如下:
- Project
-- /docker
-- nginx.dockerfile
-- php.dockerfile
--- /nginx
--- /certs
--- default.conf
--- /php
---- /conf.d
---- error_reporting.ini
---- xdebug.ini
-- /src (the laravel app)
【问题讨论】:
-
您是在运行调试器还是脚本?您是否尝试过设置断点并运行脚本(通过 CLI 或浏览器)?
-
xdebug.remote_connect_back = 1在 Xdebug 3 中不再存在。xdebug.remote_host='host.docker.internal'← 删除单引号。xdebug_info();在您尝试调试的脚本中显示什么?在 Linux 上,host.docker.internal在没有 hack 的情况下无法工作 → youtube.com/watch?v=ZIGdBSD6zvU @ 1:10 -
我赞同@Derick 他关于
xdebug_info();的建议。 Host.docker.internal(不带引号)在 macOS 上对我来说是开箱即用的。 -
啊,没错。因为 Xdebug 3 将其命名为
xdebug.client_host- 它仍然为您显示localhost,因为这是默认值。:xdebug.org/docs/upgrade_guide#changed-xdebug.remote_host -
当时我也添加了这个作为正确答案,所以其他人可以找到它。
标签: docker visual-studio-code xdebug vscode-debugger xdebug-3