【发布时间】:2022-12-19 18:51:31
【问题描述】:
我想问一下有关调试 Yii 1.1 应用程序的问题。我已经尝试在 StackOverflow 和其他网站上实现答案,但我的 VSCode 仍然无法调试应用程序,根本无法读取已设置的断点。我正在使用 Docker 来运行 Yii。
这是我使用的文件的详细信息。
docker-compose.yml
version: '3'
services:
web:
container_name: php72
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:80"
volumes:
- ./:/var/www/html
- ./xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
networks:
- app-network
mysql:
image: mysql:8.0.31-oracle
restart: always
environment:
MYSQL_ROOT_PASSWORD: '123456'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: '123456'
MYSQL_DATABASE: 'test_db'
volumes:
- db_data:/var/lib/mysql
ports:
- 3306:3306
networks:
- app-network
networks:
app-network:
volumes:
db_data:
文件
FROM php:7.2-apache
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions gd xdebug pdo pdo_mysql pdo_pgsql mongodb mbstring zip
EXPOSE 80
xdebug.ini文件
zend_extension=xdebug
[xdebug]
xdebug.mode=debug
xdebug.discover_client_host=1
xdebug.idekey=VSCODE
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.remote_host="host.docker.internal"
启动.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}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:8001"
],
"program": "",
"cwd": "${workspaceRoot}/../../",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
这是我的项目结构:
我在浏览器中使用 localhost:8000 访问我的应用程序,然后我尝试打开 VSCode 调试器,但这是结果:
很感谢任何形式的帮助。
是否缺少任何配置?
【问题讨论】:
-
1) 在调用
xdebug_info();的地方制作一些页面(URL 端点)并通过浏览器调用它(您尝试调试代码的方式)。仔细检查实际的 Xdebug 设置是否符合您的预期(也请在此处显示屏幕截图,以防出现更多不匹配)。另外:youtube.com/watch?v=IN6ihpJSFDw 2) 如果您的代码在 Docker 中,那么最好删除xdebug.discover_client_host=1行。 -
3) 根据你的第二张截图(Xdebug 日志位),Xdebug 首先尝试连接到
192.168.208.1:9003(你的自动检测到的 IP)然后回落到xdebug.client_host..这是localhost而不是预期的host.docker.internal。那是因为您使用的是 Xdebug v2 参数名称xdebug.remote_host而不是 v3 名称xdebug.client_host(检查 xdebug.org/docs/upgrade_guide )——这是您可以从#1 中发现的最明显的事情。
标签: php docker yii xdebug vscode-debugger