Page MenuHomePhabricator

XDebug not present in docker-registry.wikimedia.org/dev/stretch-php72-fpm:2.0.0
Closed, ResolvedPublic

Description

I'm not sure what exactly is going wrong here, but @mewoph reports that XDebug is not present when using the latest docker-compose.yml stack we have (wtih the web/php container split) on Docker for Mac.

Output of docker-compose exec mediawiki php --version is:

PHP 7.2.31-1+0~20200514.41+debian9~1.gbpe2a56b+wmf1 (cli) (built: May 29 2020 08:36:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.31-1+0~20200514.41+debian9~1.gbpe2a56b+wmf1, Copyright (c) 1999-2018, by Zend Technologies

.env file contents are:

MW_DOCKER_PORT=8080
MW_SCRIPT_PATH=/w
MW_SERVER=http://localhost:8080
MEDIAWIKI_USER=Admin
MEDIAWIKI_PASSWORD=dockerpass
XDEBUG_CONFIG=''
MW_DOCKER_UID=502
MW_DOCKER_GID=20

The output of phpinfo(); via the web doesn't show XDebug loaded, although there is a reference to /etc/php/7.2/fpm/conf.d/20-xdebug.ini.

I can't reproduce this on Linux (didn't try on a Mac yet) but it's not obvious to me what is wrong here.

Event Timeline

I am able to reproduce this on Docker for Mac with a fresh clone of MediaWiki core. Should I be able to see /docker/build-xdebug.sh in the container, if so, I am not seeing it, and perhaps that is a clue.

@mewoph Did you set XDEBUG_TRIGGER=1 in your request or as an environment variable? (see the Xdebug section in https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/core/+/refs/heads/master/DEVELOPERS.md)

Should I be able to see /docker/build-xdebug.sh in the container, if so, I am not seeing it, and perhaps that is a clue.

Hmm, yeah, I expect so:

15:09:08 brennen@inertia:~/code/wmf/mediawiki/core (master %=) ✴ docker-compose exec mediawiki ls /docker
20-xdebug.ini         build-xdebug.sh  php-xhprof-extension  xdebug-3.0.1.tgz
PlatformSettings.php  install.sh       www.conf

@jeena I added XDEBUG_TRIGGER=1 and XDEBUG_CONFIG=start_with_request=yes to .env. I do see build-xdebug.sh but php --version still doesn't show Xdebug.

mew-wmf@mew-wmf mediawiki % docker-compose exec mediawiki ls /docker
20-xdebug.ini	      build-xdebug.sh  php-xhprof-extension  xdebug-3.0.1.tgz
PlatformSettings.php  install.sh       www.conf

mew-wmf@mew-wmf mediawiki % docker-compose exec mediawiki php --version
PHP 7.2.31-1+0~20200514.41+debian9~1.gbpe2a56b+wmf1 (cli) (built: May 29 2020 08:36:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.31-1+0~20200514.41+debian9~1.gbpe2a56b+wmf1, Copyright (c) 1999-2018, by Zend Technologies

I am testing with a clean environment on mac now.

@mewoph can you paste the contents of your docker-compose.yml and docker-compose.override.yaml, as well as the output of docker-compose exec mediawiki env?

docker-compose.yml

# Please see DEVELOPERS.md for help
#
# Contributions to this file are welcome but please note that this file is
# minimal by design, with the idea to make it easily extensible via
# docker-compose.override.yml. For help with doing that, please see
# DEVELOPERS.md
version: '3.7'
services:
  mediawiki:
    image: docker-registry.wikimedia.org/dev/stretch-php72-fpm:2.0.0
    user: "${MW_DOCKER_UID}:${MW_DOCKER_GID}"
    volumes:
      - ./:/var/www/html/w:cached
    env_file:
      - '.env'
    environment:
      COMPOSER_CACHE_DIR: '/var/www/html/w/cache/composer'
      MW_SERVER: 'http://localhost:${MW_DOCKER_PORT:-8080}'
      MW_SCRIPT_PATH: '${MW_SCRIPT_PATH:-/w}'
      MW_DBPATH: '/var/www/html/w/cache/sqlite'
      MW_DBTYPE: 'sqlite'
      MW_LANG: 'en'
      MW_USER: '${MEDIAWIKI_USER:-Admin}'
      MW_PASS: '${MEDIAWIKI_PASSWORD:-dockerpass}'
      MW_SITENAME: 'MediaWiki'
      MW_LOG_DIR: /var/www/html/w/cache
      XDEBUG_CONFIG: '${XDEBUG_CONFIG}'
      XDEBUG_ENABLE: '${XDEBUG_ENABLE:-true}'
      XHPROF_ENABLE: '${XHPROF_ENABLE:-true}'

  mediawiki-web:
    image: docker-registry.wikimedia.org/dev/stretch-apache2:1.0.0-s1
    user: "${MW_DOCKER_UID}:${MW_DOCKER_GID}"
    ports:
      - "${MW_DOCKER_PORT:-8080}:8080"
    volumes:
      - ./:/var/www/html/w:cached
    env_file:
      - '.env'
    environment:
      MW_LOG_DIR: /var/www/html/w/cache
  mediawiki-jobrunner:
    image: docker-registry.wikimedia.org/dev/stretch-php72-jobrunner:2.0.0
    user: "${MW_DOCKER_UID}:${MW_DOCKER_GID}"
    volumes:
      - ./:/var/www/html/w:cached
    env_file:
      - '.env'
    environment:
      MW_LOG_DIR: /var/www/html/w/cache
      MW_INSTALL_PATH: /var/www/html/w
mew-wmf@mew-wmf mediawiki % docker-compose exec mediawiki env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=0f3fd34b8841
TERM=xterm
MW_DOCKER_PORT=8080
MW_SCRIPT_PATH=/w
MW_SERVER=http://localhost:8080
MEDIAWIKI_USER=Admin
MEDIAWIKI_PASSWORD=dockerpass
XDEBUG_CONFIG=start_with_request=yes
XDEBUG_TRIGGER=1
XDEBUG_ENABLE=true
XHPROF_ENABLE=true
MW_DOCKER_UID=502
MW_DOCKER_GID=20
COMPOSER_CACHE_DIR=/var/www/html/w/cache/composer
MW_DBPATH=/var/www/html/w/cache/sqlite
MW_DBTYPE=sqlite
MW_LANG=en
MW_USER=Admin
MW_PASS=dockerpass
MW_SITENAME=MediaWiki
MW_LOG_DIR=/var/www/html/w/cache
LC_ALL=C.UTF-8
PHP_VERSION=7.2
HOME=/

It turns out that we are creating the xdebug.ini with UID 1000 in the docker image, and that doesn't match up with the uid that we're passing to the mediawiki container, so it fails to enable xdebug. If you remove the user property from the mediawiki service in docker-compose.yml, you should be able to use xdebug (I think encountering other permissions issues might depend on your version of docker for mac).

We just recently added the user property for all OS due to this task https://phabricator.wikimedia.org/T273218

We'll need to fix this by rethinking how we handle permissions between the container and host operating system.

After discussion, @jeena and I think we can probably just have the equivalent of 20-xdebug.ini included from somewhere else rather than our hacky solution of having the one in /etc writable by the runuser; I'll give that a shot.

It turns out that we are creating the xdebug.ini with UID 1000 in the docker image, and that doesn't match up with the uid that we're passing to the mediawiki container, so it fails to enable xdebug. If you remove the user property from the mediawiki service in docker-compose.yml, you should be able to use xdebug (I think encountering other permissions issues might depend on your version of docker for mac).

We just recently added the user property for all OS due to this task https://phabricator.wikimedia.org/T273218

We'll need to fix this by rethinking how we handle permissions between the container and host operating system.

Thanks for looking into this so quickly. I'm wondering if we might look at abandoning the non-root concept, for example the official PHP images on Docker Hub use root by default. We already tell people not to use this setup in production, and the non-root user approach leads to various annoyances, like the UID/GID mapping issue (T273218) as well as the lack of home directory which messes up some tooling (T248802).

A workaround is to specify root user for all containers:

version: '3.7'
services:
  mediawiki:
    user: "root"
  mediawiki-web:
    user: "root"
  mediawiki-jobrunner:
    user: "root"

Then XDebug will work properly. I did a clean install -- new clone of mediawiki/core, then created my docker-compose.override.yml as noted above. The install of MediaWiki worked along with installing composer dependencies.

I just encountered this same problem after trying to spin up a new MW-docker environment from scratch. Unfortunately, @kostajh's workaround doesn't seem to fix this problem for me.

Even with the above docker-compose.override.yml file, I am unable to get XDebug working in a newly-setup MW-docker environment. When I run docker compose up without detaching, I'm seeing the following output:

mediawiki_1            | cp: cannot create regular file '/etc/php/7.2/fpm/conf.d/20-xdebug.ini': Permission denied
mediawiki_1            | cp: cannot create regular file '/etc/php/7.2/cli/conf.d/20-xdebug.ini': Permission denied
mediawiki_1            | tee: /etc/php/7.2/cli/conf.d/20-xdebug.ini: Permission denied
mediawiki_1            | tee: /etc/php/7.2/fpm/conf.d/20-xdebug.ini: Permission denied

I recently updated my Mac to Big Sur; is it possible these permissions problems are impacted by that?

@egardner which version of Docker for Mac are you using?

I'm running the latest version of the Docker Desktop app 3.3.1 which includes Docker v 20.10.5. There were a number of other changes that came with this update (docker-compose is now mostly replaced by the compose sub-command, there is a full GUI in addition to the menu-bar icon, etc).

@jeena @brennen this continues to cause problems for people. What do you think we should do? Some options I see:

  1. Try to figure out what has changed in Docker for Mac / Docker engine that is causing the permission issues when the config used to work OK
  2. Document that user: root should be used, or make it the default
  3. Adjust the images to use root user instead of nobody/nogroup

I worked on fixing this with @brennen a couple of weeks ago. Will check in during our 1:1 today.

Change 692737 had a related patch set uploaded (by Brennen Bearnes; author: Brennen Bearnes):

[releng/dev-images@master] use symlink for xdebug config file

https://gerrit.wikimedia.org/r/692737

Change 692738 had a related patch set uploaded (by Jeena Huneidi; author: Jeena Huneidi):

[mediawiki/core@master] docker-compose.yml: run as root for mediawiki

https://gerrit.wikimedia.org/r/692738

We worked on making the etc/php folder world writable (https://gerrit.wikimedia.org/r/692738) but had some other problems building the image, so I made this patch to get things working for people now: https://gerrit.wikimedia.org/r/692738

Looks like this will be needed for mwcli mwdd too, debugging was one of the things people didn't want to loose! T282363

mw mwdd mediawiki exec bash
I have no name!@mediawiki:/var/www/html/w$ php -v
PHP 7.2.31-1+0~20200514.41+debian9~1.gbpe2a56b+wmf1 (cli) (built: May 29 2020 08:36:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.31-1+0~20200514.41+debian9~1.gbpe2a56b+wmf1, Copyright (c) 1999-2018, by Zend Technologies
Addshore added a project: mwcli.
Addshore moved this task from Inbox to Watching & Blocked on the mwcli board.

Change 692737 merged by Brennen Bearnes:

[releng/dev-images@master] Xdebug: always install xdebug module, move config to core

https://gerrit.wikimedia.org/r/692737

Mentioned in SAL (#wikimedia-releng) [2021-06-22T21:25:50Z] <jeena> Updating dev-images docker-pkg files on primary contint T273682

Change 701688 had a related patch set uploaded (by Addshore; author: Addshore):

[mediawiki/tools/cli@master] Debugging: Use stretch-php72-fpm:3.0.0

https://gerrit.wikimedia.org/r/701688

Addshore claimed this task.

3.0.0 has xdebug setup well!

Change 701688 merged by jenkins-bot:

[mediawiki/tools/cli@master] Debugging: Use stretch-php72-fpm:3.0.0

https://gerrit.wikimedia.org/r/701688

Change 692738 abandoned by Jeena Huneidi:

[mediawiki/core@master] DEVELOPERS.md: run as root for mediawiki

Reason:

https://gerrit.wikimedia.org/r/692738

Change 704070 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/core@master] Update stretch-php72-fpm im MediaWiki-Docker to 3.0.0

https://gerrit.wikimedia.org/r/704070

Change 704070 merged by jenkins-bot:

[mediawiki/core@master] Update stretch-php72-fpm im MediaWiki-Docker to 3.0.0

https://gerrit.wikimedia.org/r/704070