使用Docker Compose和WordPress映像设置Xdebug [英] Setting up Xdebug with Docker Compose and WordPress image

查看:126
本文介绍了使用Docker Compose和WordPress映像设置Xdebug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用docker-compose设置Xdebug。我使用的是PhpStorm IDE,而我使用的Docker映像则安装了PHP 7.2。我正在尝试在此WordPress图片的背景下执行此操作。这是我当前的docker-compose.yml文件:

I am trying to set up Xdebug with docker-compose. I'm using PhpStorm IDE and the Docker image I'm using installs PHP 7.2. I'm trying to do this within the context of this WordPress image. Here is my current docker-compose.yml file:

    version: '3'

    services:
   db:
     image: mysql:5.7
     ports: 
       - "3306:3306"
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: somewordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   web-build-scripts:
     build: .
     depends_on:
       - db
     ports:
       - "8028:80"
       - "8029:8029"

     volumes:
       - ./themes/XXXXX:/var/www/html/wp-content/themes/XXXX
       - ./plugins/XXXX:/var/www/html/wp-content/plugins/XXXXX
       - ./plugins/XXXXX:/var/www/html/wp-content/plugins/XXXXX
       - ./plugins/XXXXX:/var/www/html/wp-content/plugins/XXXXX
       - ./plugins/XXXXX:/var/www/html/wp-content/plugins/XXXXX
       - ./plugins/XXXXX:/var/www/html/wp-content/plugins/XXXXX
       - ./plugins/XXXXX:/var/www/html/wp-content/plugins/XXXXX
       - ./plugins/XXXXX:/var/www/html/wp-content/plugins/XXXXX
       - ./plugins/XXXXX:/var/www/html/wp-content/plugins/XXXXX


     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       VIRTUAL_HOST: leasepilot.local

volumes:
    db_data:

然后将我的Dockerfile标记为web-build-scripts(当然是内置的)看起来像这样:

Then my Dockerfile which I have tagged as web-build-scripts (and built of course) looks like this:

FROM wordpress:latest

WORKDIR /var/www/html
RUN pecl install xdebug-2.6.0 \
    && docker-php-ext-enable xdebug \
    && apt-get update \
    && apt-get install nano \
    && export TERM=xterm

COPY Search-Replace-DB/ ./wp-content/Search-Replace-DB/
COPY uploads/ ./wp-content/uploads/
COPY ./docker-config/xdebug.ini ../../../usr/local/etc/php/conf.d/xdebug.ini

在本地docker-config目录中的xdebug.ini文件如下所示:

Where my xdebug.ini file that is within my docker-config directory locally looks like so:

zend_extension=xdebug.so
xdebug.default_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.remote_port=9001
xdebug.remote_enable=1
xdebug.idekey=PHPSTR
xdebug.remote_host = docker.for.mac.internal

在PHPStorm中,我已像这样设置调试设置:

并且我已经像这样设置了服务器映射:

Within PHPStorm I have set the debug settings like so: And I have set up the server mapping like so:

我也设置了就像我在xdebug.ini文件中所做的那样,将调试端口切换到9001:

I have also set the Debug Port to 9001 as I did in my xdebug.ini file:

当我运行命令php -ini | grep xdebug我的输出如下:

When I run the command php -ini | grep xdebug my output is as follows:

root@a96543427809:/var/www/html# php -ini | grep xdebug
Cannot load Xdebug - it was already loaded
/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini,
/usr/local/etc/php/conf.d/xdebug.ini
xdebug
xdebug support => enabled
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => Off => Off
xdebug.gc_stats_output_dir => /tmp => /tmp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => PHPSTR => PHPSTR
xdebug.max_nesting_level => 256 => 256
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => docker.for.mac.internal => docker.for.mac.internal
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9001 => 9001
xdebug.remote_timeout => 200 => 200
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

我已经看过几本教程,但还没弄清楚。有人有什么见解可以帮助我吗?

I've gone through several tutorials and haven't been able to figure this out. Anyone hav any insights that may help me?

推荐答案

我会做什么


  • 首先,您使用的是 wordpress:latest ,因此您必须查找您的wordpress图像正在运行的php
    版本。

  • 然后在容器中安装了 xdebug

  • 使用 xdebug 安装来创建 Dockerfile ,请勿将其用于生产,这会降低您的性能。

  • 从该 Dockerfile 您的wordpress 映像$ c>。

  • 您可能需要使用远程主机详细信息创建 xdebug.ini 文件,我正在使用phpstrom是我的 xdebug.ini 的样子。我将此文件保留在主机中,并使用 volumes 复制。

  • First you are using wordpress:latest so you have to find which php version your wordpress image is running.
  • Then check is xdebug is installed in the container. Most probably not!
  • Create a Dockerfile with xdebug installation for the development, dont use this for production, it will slow down your performance.
  • Build your-wordpress image from that Dockerfile.
  • You might need to create the xdebug.ini file with your remote host details, i'm using phpstrom this is what my xdebug.ini looks like. I keep this file in my host machine and copy it with volumes.

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=10000 # dont use 9000 its usually used by the php-fpm
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.idekey=PHPSTRM
xdebug.remote_host=host-ip-here


这就是我的docker-compose文件的样子

This is how my docker-compose file looks like


version: '2'
services:
    my-service:
        build:
          context: ./dev
          dockerfile: Dockerfile
        ports:
            - "8080:80"
        restart: always
        environment:
            - RUNTIME_ENVIRONMENT=local
        working_dir: /src
        volumes:
            - ./src:/src
            - ./php-ini-overrides-dev.ini/xdebug.ini:/etc/php/7.1/mods-available/xdebug.ini





  • 然后使用 xdebug.ini 详细信息配置phpstorm远程调试。

  • 要确保xdebug配置已加载,请登录容器并运行 php -ini | grep xdebug

  • 这是使 xdebug 工作的一种方法。

  • 如果无法正常运行,请启用xdebug日志,将 xdebug.remote_log = / log_path / xdebug.log 添加到xdebug.ini将有助于诊断问题。

  • 让我知道您是否还需要帮助来设置phpstorm远程调试。其实那里有很多资源。

    • Then configure phpstorm remote debugging with xdebug.ini details.
    • To make sure xdebug config loaded, log into container and run php -ini | grep xdebug
    • This is one way of getting xdebug works.
    • If its not working enable xdebug log, add xdebug.remote_log=/log_path/xdebug.log to xdebug.ini will help to diagnose the issue.
    • Let me know if you also need help with setuping the phpstorm remote debugging. Actually there are lots of resources out there.
    • 这篇关于使用Docker Compose和WordPress映像设置Xdebug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆