【问题标题】:Configuring Xdebug with docker compose使用 docker compose 配置 Xdebug
【发布时间】: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


【解决方案1】:

我和你有同样的问题

对于我的情况,将这些配置放在ini 中是不够的,我需要将 xdebug 配置放入 docker-compose.yml,它看起来像:

services:
  Wordpress:
    ...
    environment:
      XDEBUG_CONFIG: remote_host=host.docker.internal remote_port=9003 remote_enable=1

xdebug 2.7.0, php 7.0, 可视化代码 1.72.1 (php debug ext v1.29.0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2020-04-30
    • 2022-10-09
    相关资源
    最近更新 更多