3

How can I "attach" xdebug to drush in a docker container?

By that I mean, how can I have xdebug show me a history of an import script? And to look at the single variables that are defined and occupied during the import script?

The whole thing runs on: Docker version 2.1.05 (40693), Engine: 19.03.5, running on Mac 10.15.1. Drupal version 8.7.9.
PhpStorm, Version 2019.3

My Config tempter, here the file docker-compose.yml:

version: "3.4"

services:
  mariadb:
    image: wodby/mariadb:$MARIADB_TAG
    container_name: "${PROJECT_NAME}_mariadb"
    stop_grace_period: 30s
    environment:
      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD
    ports:
      - "4306:3306"
  mysql:
    image: wodby/mariadb:$MARIADB_TAG
    container_name: "${PROJECT_NAME}_mariadb_test"
    stop_grace_period: 30s
    environment:
      MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
      MYSQL_DATABASE: $DB_NAME
      MYSQL_USER: $DB_USER
      MYSQL_PASSWORD: $DB_PASSWORD

  php:
    image: wodby/drupal-php:$PHP_TAG
    container_name: "${PROJECT_NAME}_php"
    environment:
      PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025
      DB_HOST: $DB_HOST
      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.

### From here the config of the Xdebug:
  PHP_XDEBUG: 1
      PHP_XDEBUG_DEFAULT_ENABLE: 1
      PHP_XDEBUG_REMOTE_AUTOSTART: 1
      PHP_XDEBUG_REMOTE_HOST: host.docker.internal # Docker 18.03+ Mac/Win
      PHP_IDE_CONFIG: serverName=Docker
      PHP_XDEBUG_REMOTE_CONNECT_BACK: 1
    volumes:
      - ./:/var/www/html

 nginx:
  image: wodby/nginx:$NGINX_TAG
  container_name: "${PROJECT_NAME}_nginx"
  depends_on:
    - php
  environment:
    NGINX_STATIC_OPEN_FILE_CACHE: "off"
    NGINX_ERROR_LOG_LEVEL: debug
    NGINX_BACKEND_HOST: php
    NGINX_SERVER_ROOT: /var/www/html/docroot
    NGINX_VHOST_PRESET: $NGINX_VHOST_PRESET
  volumes:
    - ./:/var/www/html
  labels:
    - 'traefik.backend=${PROJECT_NAME}_nginx'
    - 'traefik.port=80'
    - 'traefik.frontend.rule=Host:${PROJECT_BASE_URL}'


 selenium-firefox:
  container_name: "${PROJECT_NAME}_firefox"
  image: selenium/standalone-firefox-debug:2.53.1
  volumes:
    # - /dev/shm:/dev/shm
    - ./:/var/www/html
  ports:
    - "5905:5900"
    - "4444:4444"

 mailhog:
  image: mailhog/mailhog
  container_name: "${PROJECT_NAME}_mailhog"
  labels:
    - 'traefik.backend=${PROJECT_NAME}_mailhog'
    - 'traefik.port=8025'
    - 'traefik.frontend.rule=Host:mailhog.${PROJECT_BASE_URL}'

memcached:
  container_name: "${PROJECT_NAME}_memcached"
  image: wodby/memcached:$MEMCACHED_TAG
  command: "sh -c 'memcached -m 1024'"


portainer:
  image: portainer/portainer
  container_name: "${PROJECT_NAME}_portainer"
  command: --no-auth -H unix:///var/run/docker.sock
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  labels:
    - 'traefik.backend=${PROJECT_NAME}_portainer'
    - 'traefik.port=9000'
    - 'traefik.frontend.rule=Host:portainer.${PROJECT_BASE_URL}'

traefik:
  image: traefik:v1.7-alpine
  container_name: "${PROJECT_NAME}_traefik"
  command: -c /dev/null --web --docker --logLevel=INFO
  ports:
    - '80:80'
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock

 php_test:
  container_name: "${PROJECT_NAME}_php_test"
  image: registry.my_projekt.de/drupal-test
  volumes:
    - ./:/var/www/html
  environment:
    CI_PROJECT_DIR : "/var/www/html/"
    DATABASE_PATH: "/root/database.sql"
    SELENIUM_PORT: "4444"
    BROWSER: "firefox"
    WEB_DRIVE: ""
    DISPLAY: ":99"
    UPDATE_ALIAS: "myProjekt:update"
    DB_HOST: 'mysql'
  labels:
    - 'traefik.port=80'
    - 'traefik.frontend.rule=Host:test.${PROJECT_BASE_URL}'

 php_quality:
  image: hussainweb/drupal-code-quality:latest
  command: tail -f /dev/null
  volumes:
    - ./:/var/www/html
  • You should add what IDE are you using (vi, Netbeans, Eclipse, PhpStorm, etc). – sanzante Dec 12 '19 at 11:08
  • oh, sorry, I forgot, PhpStorm, Version 2019.3 – webuser57 Dec 12 '19 at 11:45
0

It can happen if you are using drush launcher (https://github.com/drush-ops/drush-launcher). This tool allows you to type "drush" in your Drupal directory, instead of "./vendor/bin/drush", but it can confuse xdebug. Using "./vendor/bin/drush" may fix the problem.

Additionally, you may also have to set an environment variable in your PHP container:

export PHP_IDE_CONFIG="serverName=my_server"

... where my_server is the name of the server in

Preferences / Languages & Frameworks / PHP / Servers

where your path mapping is set in PHP storm.

You may also wish to enable the option: "Break at first line in PHP scripts" and then run your drush commands - as often it can be tricky to set breakpoints in the correct place when running drush.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.