我正在尝试使用 Apache 在 GitPod 上运行 Xdebug 3。安装效果很好,还有“在当前打开的脚本上启动”。
挑战是将 Xdebug 连接到调试客户端。由于 Docker 环境的原因,如果只使用
xdebug.client_host = localhost
,这似乎会失败。通常人们会使用 xdebug.client_host = host.docker.internal
,但只是简单地声明这在 GitPod 上不起作用。
.gitpod.yml
image:
file: .gitpod.dockerfile
context: apache
ports:
- port: 8080
onOpen: open-preview
- port: 9003
onOpen: ignore
tasks:
- name: Apache
command: >
apachectl start &&
multitail /var/log/apache2/access.log -I /var/log/apache2/error.log
vscode:
extensions:
- felixfbecker.php-debug
.gitpod.Dockerfile:
FROM gitpod/workspace-full:latest
# install corresponding PHP Xdebug
RUN sudo install-packages php-xdebug
# Copy the Xdebug configuration into the container
COPY xdebug.ini /etc/php/8.2/cli/conf.d/20-xdebug.ini
# optional: use a custom apache config.
COPY apache.conf /etc/apache2/apache2.conf
# optional: change document root folder. It's relative to your git working copy.
ENV APACHE_DOCROOT_IN_REPO="www"
xdebug.ini:
zend_extension = xdebug
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal
xdebug.log = ${GITPOD_REPO_ROOT}/xdebug.log
这是launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
}
]
}
我认为 tmy2017/php-ddd-cargo-sample
通过xdebug.ini
显示了一些解决方案,但我不知道如何在我的用例中实现这个?docker run --add-host host.docker.internal:host-gateway
要在 Gitpod 设置中实现此功能,您可能需要更新自定义 Docker 映像并合并类似的
extra_hosts
配置。
.gitpod.dockerfile
:
FROM gitpod/workspace-full:latest
# rest of your code
# Add extra_hosts configuration
RUN echo "extra_hosts:" >> /etc/docker/daemon.json && \
echo " - host.docker.internal:host-gateway" >> /etc/docker/daemon.json
# rest of your code
这将包括
extra_hosts
配置,类似于所提供的 GitHub 提交中的 docker-compose.yml
中的配置。host.docker.internal
是否可以在您的 Gitpod 环境中正确解析。