简体   繁体   English

文件夹映射时,XDebug 无法使用 WordPress 容器

[英]XDebug not working with WordPress container when folder mapped

I have a WordPress running on a docker-composer, and I would like to be able to debug it.我有一个 WordPress 在 docker-composer 上运行,我希望能够调试它。

I used this repository as a basis Wordpress Docker xDebug Boilerplate and I have changed some things.我使用这个存储库作为基础Wordpress Docker xDebug Boilerplate并且我改变了一些东西。

This is my docker-compose:这是我的 docker-compose:

version: '3.9'

services:

  db:
    platform: linux/x86_64
    image: mysql:8.0
    container_name: db
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
      - 3306:3306
    environment:
      MYSQL_USER: db_user
      MYSQL_PASSWORD: db_password
      MYSQL_DATABASE: db_name
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - db_data:/var/lib/mysql

  wordpress:
    depends_on:
      - db
    build: .
    image: wordpress:latest
    restart: always
    ports:
      - 8888:80
    env_file: .env
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: db_name
      WORDPRESS_DB_USER: db_user
      WORDPRESS_DB_PASSWORD: db_password
      PHP_EXTENSION_XDEBUG: wp_password
    volumes:
      - wp_data:/var/www/html
      - ./wp-content/:/var/www/html/wp-content/

volumes:
  db_data:
  wp_data:


My Dockerfile:我的 Dockerfile:

FROM wordpress:latest

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug \
    && echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.client_host = host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

And I have some content inside a folder I called wp-content , that I have created at the root of the project:我在项目根目录下创建的名为wp-content的文件夹中有一些内容:

  • a folder plugins一个文件夹plugins
    • a index.php file一个index.php文件
  • a folder themes文件夹themes
    • a folder default文件夹default
      • a index.php file一个index.php文件
      • a style.css file一个style.css文件

My problem is: when mapping the folder wp-content , the debugger does not work.我的问题是:映射文件夹wp-content时,调试器不起作用。 I have checked the port configuration and etc.我检查了端口配置等。

I am using VSCode, here is my launch.json file:我正在使用 VSCode,这是我的 launch.json 文件:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/var/www/html": "${workspaceFolder}/cms"
      },
      "xdebugSettings": {
        "max_data": 65535,
        "show_hidden": 1,
        "max_children": 100,
        "max_depth": 5
      }
    }
  ]
}

However, if the content of /var/www/html is mapped entirely for another folder (for example cms ), it works perfectly.但是,如果/var/www/html的内容完全映射到另一个文件夹(例如cms ),它就可以完美运行。

# wordpress service
    volumes:
      - './cms:/var/www/html'

How can I make the debugger work copying the wp-content to inside the WordPress container?如何让调试器将 wp-content 复制到 WordPress 容器内?

I had to add loads of config before mine magically worked: after PECL install在我神奇地工作之前,我必须添加大量配置:在 PECL 安装之后

# install xdebug
RUN echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

RUN echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_host=docker.for.win.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo 'xdebug.mode=debug' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.client_host=host.docker.internal' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.remote_autostart=0' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.remote_enable=1' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.default_enable=0' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.remote_host=host.docker.internal' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.remote_port=' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.remote_connect_back=0' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.profiler_enable=0' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.remote_log="/tmp/xdebug.log"' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.profiler_output_dir="/var/www/html/profiler"' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.profiler_output_name="cachegrind.out.%p"' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.cli_color=1' > /usr/local/etc/php/php.ini
RUN echo 'xdebug.profiler_append=1' > /usr/local/etc/php/php.ini

Well, the problem was that I had the wrong config at the launch.json file.好吧,问题是我在launch.json文件中的配置错误。 My pathMapping was set to listen to cms folder.我的pathMapping被设置为监听cms文件夹。

I just had to change from $worspaceFolder}/cms to $worspaceFolder}/wp-content .我只需要从$worspaceFolder}/cms更改为$worspaceFolder}/wp-content

Here is the correct launch.json :这是正确的launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "pathMappings": {
        "/var/www/html/wp-content": "${workspaceFolder}/wp-content"
      },
      "xdebugSettings": {
        "max_data": 65535,
        "show_hidden": 1,
        "max_children": 100,
        "max_depth": 5
      }
    }
  ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM