skip to Main Content

I have started to play with my first Laravel project on a MacOS. I am using Laravel Sail for running the project inside a container and everything seems to work except the debugging part.

Versions used:

  • Laravel 8.66,
  • PHP 8.0.12,
  • Xdebug 3.1.1

According to Laravel docs we can set SAIL_XDEBUG_MODE to enable the debug mode. However, the debugging is not working in PhpStorm even if it is set to listen for incoming connections. I have seen that running php -i in container returns different configs for Xdebug comparing to what we see in phpinfo() from browser even if the Configuration file is the same one.

Here are some screenshots from browser:

WEB - PHP configuration files
WEB - PHP Xdebug configs

Here are screenshots from what I see in the command line:

CLI - PHP configuration files
CLI - PHP Xdebug configs

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. Is is possible to have the same configs in console and browser via SAIL_XDEBUG_MODE ?

This is the Dockerfile that is used:

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"]

And this is my 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

2

Answers


  1. 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 uses XDEBUG_MODE if it is set, otherwise it falls back to the value of the xdebug.mode setting.

    I don’t know which web server Sail uses, but some will strip out the environment variables — including XDEBUG_MODE.

    So you can either fix that, or update the Dockerfile to add a line below:

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

    Which says:

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

    And add to the contents of xdebug.ini (in the same directory as php.ini):

    xdebug.mode=develop,debug
    
    Login or Signup to reply.
  2. I had the same problem and I’m also on macOS.

    You must use the export command, like this:

    export SAIL_XDEBUG_MODE=develop,debug
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search