gpt4 book ai didi

php - Laravel SAIL_XDEBUG_MODE 不适用于调试网络调用

转载 作者:行者123 更新时间:2023-12-05 03:35:59 25 4
gpt4 key购买 nike

我已经开始在 MacOS 上玩我的第一个 Laravel 项目。我正在使用 Laravel Sail 在容器内运行项目,除了调试部分外,一切似乎都正常。

使用的版本:

  • Laravel 8.66,
  • PHP 8.0.12,
  • Xdebug 3.1.1

根据 Laravel docs我们可以设置SAIL_XDEBUG_MODE来启用调试模式。但是,调试在 PhpStorm 中不起作用,即使它设置为监听传入连接。即使配置文件同上。

以下是浏览器的一些截图:

WEB - PHP configuration files WEB - PHP Xdebug configs

以下是我在命令行中看到的屏幕截图:

CLI - PHP configuration files CLI - PHP Xdebug configs

如所附屏幕截图所示,在控制台中使用了 XDEBUG_MODE 环境变量,而在浏览器中使用了 xdebug.mode。是否可以通过 SAIL_XDEBUG_MODE 在控制台和浏览器中使用相同的配置?

这是使用的 Dockerfile:

FROM ubuntu:21.04

LABEL maintainer="Taylor Otwell"

ARG WWWGROUP

WORKDIR /var/www/html

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E5267A6C \
&& apt-key adv --homedir ~/.gnupg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C300EE8C \
&& echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu hirsute main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.0-cli php8.0-dev \
php8.0-pgsql php8.0-sqlite3 php8.0-gd \
php8.0-curl php8.0-memcached \
php8.0-imap php8.0-mysql php8.0-mbstring \
php8.0-xml php8.0-zip php8.0-bcmath php8.0-soap \
php8.0-intl php8.0-readline php8.0-pcov \
php8.0-msgpack php8.0-igbinary php8.0-ldap \
php8.0-redis php8.0-swoole php8.0-xdebug \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y nodejs \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y yarn \
&& apt-get install -y mysql-client \
&& apt-get install -y postgresql-client \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0

RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail

COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container

EXPOSE 8000

ENTRYPOINT ["start-container"]

这是我的 docker-compose.yml:

# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
PHP_IDE_CONFIG: "serverName=my.local"
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local

最佳答案

As it can be seen in the attached screenshots, in console is used the XDEBUG_MODE env var, while in browser is used xdebug.mode.

Xdebug 使用 XDEBUG_MODE 如果它被设置,否则它回落到 xdebug.mode 设置的值。

我不知道 Sail 使用哪个 Web 服务器,但有些服务器会去掉环境变量 — 包括 XDEBUG_MODE

因此您可以修复该问题,或更新 Dockerfile 以在下面添加一行:

COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini

上面写着:

COPY xdebug.ini /etc/php/8.0/cli/conf.d/999-xdebug.ini

并在xdebug.ini的内容中添加(与php.ini同目录):

xdebug.mode=develop,debug

关于php - Laravel SAIL_XDEBUG_MODE 不适用于调试网络调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69739346/

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