1

What I am trying to do:

I am trying to run/debug unit tests within PhpStorm 2020.3, on Laravel 8. The ENV is WSL 2 on Windows 10.

Problem(s)

One: PHP and Xdebug is not detected when I select the service in CLI interpreters. enter image description here

Two: When I run/debug unit tests, I get different errors, one of which:

[docker-compose://[\\wsl$\Ubuntu-20.04\home\musa\codes\boom\finance\docker-compose.yml]:laravel.test/]:php /opt/.phpstorm_helpers/phpunit.php --configuration /var/www/html/phpunit.xml
Testing started at 8:31 PM ...
Version mismatch: file \\wsl$\Ubuntu-20.04\home\musa\codes\xyz\docker-compose.yml specifies version 3.9 but extension file C:\Users\musah\AppData\Local\JetBrains\PhpStorm2020.3\tmp\docker-compose.override.9.yml uses version 1

Process finished with exit code 1

I suppose the 2nd problem will be fixed if I can fix the first one.

Details:

docker-compose.yml file:

services:
  laravel.test:
    build:
      context: ./docker/development
      dockerfile: Dockerfile
      args:
        WWWGROUP: '${WWWGROUP:-wwwdata}'
    image: sail-8.0/app
    ports:
      - '${APP_PORT:-80}:80'
      - '9003:9003'
    environment:
      WWWUSER: '${WWWUSER:-wwwdata}'
      LARAVEL_SAIL: 1
    volumes:
      - '.:/var/www/html'
      - './docker/development/xdebug.ini:/usr/local/etc/php/conf.d/php-ext-xdebug.ini'
      - './docker/development/php.ini:/usr/local/etc/php/conf.d/99-sail.ini'
      - './docker/development/http.conf:/etc/apache2/sites-available/000-default.conf'
      - './docker/development/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf'
    networks:
      - sail
    depends_on:
      - mysql
      - redis
      - selenium
  mysql:
    image: mysql:5.7.29
    restart: unless-stopped
    tty: true
    ports:
      - '${FORWARD_DB_PORT:-3306}:3306'
    volumes:
      - ./docker/development/mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
      MYSQL_DATABASE: '${DB_DATABASE}'
      MYSQL_USER: '${DB_USERNAME}'
      MYSQL_PASSWORD: '${DB_PASSWORD}'
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
      SERVICE_NAME: mysql
    networks:
      - sail
    healthcheck:
      test: ["CMD", "mysqladmin", "ping"]
  redis:
    image: 'redis:alpine'
    ports:
      - '${FORWARD_REDIS_PORT:-6379}:6379'
    volumes:
      - 'sailredis:/data'
    networks:
      - sail
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]

  mailhog:
    image: 'mailhog/mailhog:latest'
    ports:
      - '${FORWARD_MAILHOG_PORT:-1025}:1025'
      - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
    networks:
      - sail

  selenium:
    image: 'selenium/standalone-chrome:latest'
    volumes:
      - '/dev/shm:/dev/shm'
    networks:
      - sail

  localstack:
    image: localstack/localstack:latest
    environment:
      - AWS_DEFAULT_REGION=us-east-1
      - EDGE_PORT=4566
      - SERVICES=lambda,s3
    ports:
      - '4566:4566'
    volumes:
      - "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
      - "/var/run/docker.sock:/var/run/docker.sock"
    networks:
      - sail

networks:
  sail:
    driver: bridge

volumes:
  sailmysql:
    driver: local
  sailredis:
    driver: local
  sailmeilisearch:
    driver: local

docker/development/Dockerfile file:

FROM php:8.0-apache

ARG WWWGROUP

WORKDIR /var/www/html

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update \
    && apt-get install -y curl zip unzip supervisor libcap2-bin libpng-dev python2 \
    && php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
    && apt-get -y autoremove \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN pecl install xdebug && docker-php-ext-enable xdebug

RUN setcap "cap_net_bind_service=+ep" /usr/local/bin/php

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
RUN chmod +x /usr/local/bin/start-container

EXPOSE 8000
EXPOSE 9003

ENTRYPOINT ["start-container"]

docker/development/php.ini file:

[PHP]
post_max_size = 100M
upload_max_filesize = 100M
variables_order = EGPCS

docker/development/xdebug.ini file:

[XDebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
xdebug.log = "/tmp/xdebug.log"

docker/development/supervisord.conf file:

[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid

[program:php]
command=/usr/local/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80
user=sail
environment=LARAVEL_SAIL="1"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

docker/development/start-container file:

#!/usr/bin/env bash

if [ ! -z "$WWWUSER" ]; then
    usermod -u $WWWUSER sail
fi

if [ ! -d /.composer ]; then
    mkdir /.composer
fi

chmod -R ugo+rw /.composer

if [ $# -gt 0 ];then
    exec gosu $WWWUSER "$@"
else
    /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi

1 Answer 1

1

To my surprise both the problems were fixed by specifying the version in docker-compose.yml file as:

version: '3.9'
services:
  laravel.test:
    build:
      context: ./docker/development
      dockerfile: Dockerfile
      args:
...

Reference: https://youtrack.jetbrains.com/issue/PY-38394

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.