gpt4 book ai didi

php - 使用 Docker Compose 和 WordPress 镜像设置 Xdebug

转载 作者:行者123 更新时间:2023-12-01 23:08:41 25 4
gpt4 key购买 nike

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

    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:

然后我标记为 web-build-scripts(当然是构建的)的 Dockerfile 看起来像这样:
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 文件如下所示:
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 中,我设置了如下调试设置:
enter image description here
我已经像这样设置了服务器映射:
enter image description here

我还像在 xdebug.ini 文件中一样将调试端口设置为 9001:
enter image description here

当我运行命令 php -ini | grep xdebug 我的输出如下:
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

我已经浏览了几个教程,但无法弄清楚这一点。任何人都有任何可以帮助我的见解?

最佳答案

我会怎么做

  • 首先您使用的是 wordpress:latest所以你必须找到哪个php
    您的 wordpress 图像正在运行的版本。
  • 然后检查是xdebug安装在容器中。很可能不是!
  • 创建一个 Dockerfilexdebug安装用于开发,请勿将其用于生产,它会降低您的性能。
  • 从中构建您的 wordpress 图像 Dockerfile .
  • 您可能需要创建 xdebug.ini包含远程主机详细信息的文件,我正在使用 phpstrom 这就是我的 xdebug.ini好像。我将此文件保存在我的主机中并使用 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 文件的样子

    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 远程调试方面还需要帮助,请告诉我。其实里面有很多资源。
  • 关于php - 使用 Docker Compose 和 WordPress 镜像设置 Xdebug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52995837/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com