EDIT-2 2018
现在可以更改 remote_host 值以支持所有平台:
xdebug.remote_host = "host.docker.internal"
EDIT-1 2018
不再需要使用 plist 修复程序。正如本要点中所指出的:https://gist.github.com/chadrien/c90927ec2d160ffea9c4#gistcomment-2398281 您现在可以将 docker 用于 mac 内部 IP。
[xdebug]
xdebug.remote_host = "docker.for.mac.host.internal"
xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000
xdebug.idekey="PHPSTORM"
旧配置
由于您在 Mac 上使用 docker,因此我发布了我的解决方案的工作方式。大部分学分归this post on the docker forum。
假设您的 xdebug 安装正确,这是我在 php.ini 中的配置。
[xdebug]
xdebug.remote_host=10.254.254.254
xdebug.remote_autostart=1
xdebug.idekey = PHPSTORM
xdebug.default_enable = 0
xdebug.remote_enable = 1
xdebug.remote_connect_back = 0
xdebug.profiler_enable = 1
您可以通过在终端中执行此命令来测试您的配置。 sudo ifconfig en0 alias 10.254.254.254 255.255.255.0。
如果这有效,您可以将其转换为plist 文件并将其放置在以下位置。 /Library/LaunchDaemons/com.docker.xdebugFix.plist。您将在下面找到我的 plist 文件版本。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.docker.xdebugFix</string>
<key>ProgramArguments</key>
<array>
<string>ifconfig</string>
<string>en0</string>
<string>alias</string>
<string>10.254.254.254</string>
<string>255.255.255.0</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
注意:plist 仅在您的 Mac 重新启动后才能工作。
PHPSTORM 配置(2018 年修改后也需要)
之后,我用这样的调试服务器设置了我的 PHP Storm:
在我的断点工作之后,如果您使用的是 chrome,您还需要使用 xdebug 扩展,但我很确定您知道这一点,因为您过去使用过它。