【发布时间】:2022-11-11 09:48:25
【问题描述】:
我正在尝试使用 docker-compose 和 Xdebug 配置 WordPress 开发环境,但在 VSCode 中启动调试会话后,我无法让调试器在 info.php 文件上使用简单的断点。
这是我的配置:
dockerfile
FROM php:7.4-apache
RUN docker-php-ext-install mysqli
RUN pecl install xdebug
php.ini
zend_extension=xdebug.so
xdebug.profiler_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9003
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.idekey=VSCODE
码头工人-compose.yml
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
build: .
volumes:
- ./wp:/var/www/html
- ./php.ini:/usr/local/etc/php/php.ini
ports:
- "80:80"
restart: always
environment:
PHP_EXTENSION_DEBUG: 1
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wp: {}
.vscode/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,
"pathMappings": {
"/var/www/html":"${workspaceFolder}/wp"
}
},
{
"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:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
我按照this tutorial 执行完全相同的步骤,但仍然无法进行分步调试。
【问题讨论】:
-
“xdebug.remote_host=host.docker.internal xdebug.remote_port=9003”你的 Xdebug 版本是什么?很可能是 Xdebug v3。如果我是对的,那么问题是——您的 Xdebug 配置 (php.ini) 适用于 Xdebug v2。但是 v3 更改了参数名称和值。您当前的配置在 v3 中几乎没有任何作用。通过xdebug.org/docs/upgrade_guide 并调整您的配置以使用 Xdebug v3 参数。附言也可以查看matthewsetter.com/setup-step-debugging-php-xdebug3-docker 或其他一些文章
-
您可以从
xdebug_info()输出(用于 Xdebug v3)检查您当前/实时的 Xdebug 配置——因此您可以查看使用的值是否与您放入配置的值正确。对于旧的 Xdebug v2,这将是phpinfo()输出的专用 Xdebug 部分。
标签: php wordpress docker docker-compose xdebug