gpt4 book ai didi

php - 使用 XDebug、VSCode 和 Docker 进行调试

转载 作者:行者123 更新时间:2023-12-05 07:16:48 28 4
gpt4 key购买 nike

我正尝试在来自 docker4drupal 的 Docker 中配置 XDebug和 VSCode,尽管我遵循了这个,但我什么也没得到:

这是我的 docker-compose.yml

php:
image: wodby/drupal-php:$PHP_TAG
container_name: "${PROJECT_NAME}_php"
environment:
PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
# PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S opensmtpd:25
DB_HOST: $DB_HOST
DB_PORT: $DB_PORT
DB_USER: $DB_USER
DB_PASSWORD: $DB_PASSWORD
DB_NAME: $DB_NAME
DB_DRIVER: $DB_DRIVER
PHP_FPM_USER: wodby
PHP_FPM_GROUP: wodby
COLUMNS: 80 # Set 80 columns for docker exec -it.
# ## Read instructions at https://wodby.com/docs/stacks/php/local/#xdebug
PHP_XDEBUG: 1
PHP_XDEBUG_DEFAULT_ENABLE: 1
# # PHP_XDEBUG_REMOTE_CONNECT_BACK: 0
# # PHP_IDE_CONFIG: serverName=my-ide
PHP_XDEBUG_IDEKEY: "VSCODE"
PHP_XDEBUG_REMOTE_HOST: host.docker.internal # Docker 18.03+ Mac/Win
# # PHP_XDEBUG_REMOTE_HOST: 172.17.0.1 # Linux
# PHP_XDEBUG_REMOTE_HOST: 10.254.254.254 # macOS, Docker < 18.03
# PHP_XDEBUG_REMOTE_HOST: 10.0.75.1 # Windows, Docker < 18.03
# PHP_XDEBUG_REMOTE_LOG: /tmp/php-xdebug.log
## PHPUnit Drupal testing configurations
# SIMPLETEST_BASE_URL: "http://nginx"
# SIMPLETEST_DB: "${DB_DRIVER}://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}#tests_"
# MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","goog:chromeOptions":{"args":["--disable-gpu","--headless"]}}, "http://chrome:9515"]'

volumes:
- ../drupal:/var/www/html
## For macOS users (https://wodby.com/docs/stacks/drupal/local#docker-for-mac)
# - ./:/var/www/html:cached # User-guided caching
# - docker-sync:/var/www/html # Docker-sync
## For XHProf and Xdebug profiler traces
# - files:/mnt/files

我的 launch.json

{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html": "/Users/oskar/Webapps/Docker/project/drupal",
"/var/www/html/web": "/Users/oskar/Webapps/Docker/project/drupal/web"
},
"xdebugSettings": {
"max_data": 65535,
"show_hidden": 1,
"max_children": 100,
"max_depth": 5
}
}
]
}

我在 .vscode/launch.json 中有 launch.json

另外我的结构是:

/Users/oskar/Webapps/Docker/project/drupal/
/Users/oskar/Webapps/Docker/project/docker/

当我尝试运行调试时,我什么也没得到。

最佳答案

我知道这是旧的,但既然我已经开始工作了,我想我会为其他人留下足迹。这是我必须为 php-apache 容器放入 Dockerfile 的内容

# enable xdebug
RUN docker-php-ext-enable xdebug

# precreate log file for xdebug
RUN echo " " >> xdebug.log \
&& chown www-data:www-data xdebug.log \
&& chmod 774 xdebug.log \
# precreate directory for xdebug profiler
&& mkdir profiles \
&& chown www-data:www-data profiles \
&& chmod 774 profiles\
# precreate directory for xdebug tracer
&& mkdir traces \
&& chown www-data:www-data traces \
&& chmod 774 traces

# create and move xdebug.ini initialization file to start up dir
# Add Xdebug to PHP configuration
# See https://xdebug.org/docs/all_settings
RUN echo "" >> xdebug.ini \
&& echo "[xdebug]" >> xdebug.ini \
&& echo "zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so" >> xdebug.ini \
&& echo "xdebug.remote_enable = 1" >> xdebug.ini \
#profile setting
&& echo "xdebug.profiler_enable = 0" >> xdebug.ini \
# use url param XDEBUG_PROFILE nothing or secret found in profile_enable_trigger_value
&& echo "xdebug.profiler_enable_trigger = 1" >> xdebug.ini \
&& echo "xdebug.profiler_output_name = readxdebug.out.%t.pro" >> xdebug.ini \
&& echo "xdebug.profiler_output_dir = /usr/local/etc/php/profiles" >> xdebug.ini \
#trace setting
&& echo "xdebug.trace_enable_trigger = 1" >> xdebug.ini \
# use url param XDEBUG_TRACE nothing or secret found in trace_enable_trigger_value
&& echo "xdebug.trace_output_name = readtrace.%c" >> xdebug.ini \
&& echo "xdebug.trace_output_dir = /usr/local/etc/php/traces" >> xdebug.ini \
#
&& echo "xdebug.remote_autostart = 1" >> xdebug.ini \
&& echo "xdebug.remote_host = host.docker.internal" >> xdebug.ini\
&& echo "xdebug.default_enable=1" >> xdebug.ini\
&& echo "xdebug.remote_port=9000" >> xdebug.ini\
&& echo "xdebug.remote_connect_back=0" >> xdebug.ini\
&& echo "xdebug.idekey=VSCODE" >> xdebug.ini\
&& echo "xdebug.remote_log=/usr/local/etc/php/xdebug.log" >> xdebug.ini\
&& mv xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

我将 XDEBUG 配置为使用 url 参数 XDEBUG_PROFILE 和跟踪来触发配置文件使用 url 参数 XDEBUG_TRACE。

我还使用以下命令将配置文件或跟踪输出文件移动到给定项目的映射目录

docker exec -t docker_myprojapp_1 bash -c "mv /usr/local/etc/php/profiles/*.xt /var/
www/html/projectname/dev/profiles/"

docker exec -t docker_myprojapp_1 bash -c "mv /usr/local/etc/php/traces/*.xt /var/
www/html/projectname/dev/traces/"

关于php - 使用 XDebug、VSCode 和 Docker 进行调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59079611/

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