环境 | 版本 |
php | ^7.2 |
xdebug | 3 |
docker | 20.10.21 |
如果 mac 使用了 docker desktop 的话,直接配置的话,是 bridge 网络模式,如果直接将端口9003映射出来的话,启动 vscode 的 xdebug 是无法进行调试的,配置如下,启动之后会返回端口被占用的错误
[xdebug]
[XDebug]
xdebug.mode = debug,profile,develop,trace
xdebug.start_with_request = yes
xdebug.discover_client_host = 1
xdebug.client_host = 192.168.1.100
[vscode]
{
"name": "php-Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
...
},
},
我们需要将相关的配置调整如下
[xdebug]
[XDebug]
xdebug.mode = debug,profile,develop,trace
xdebug.start_with_request = yes
xdebug.discover_client_host = 1
xdebug.client_host = docker.for.mac.localhost
其中 docker.for.mac.localhost 是 docker 中内置的本地 ip 地址