docker-magento: can't enable xdebug, phpfpm container is recreated on restart.

Description

When I try to enable the xdebug with bin/xdebug enable and the phpfpm service is restarted the container is recreated, and the value back to the original state.

  • OS: ubuntu.
  • Docker version 23.0.1, build a5ee5b1

Steps To Reproduce

  1. bin/xdebug enable

Expected Result

$ bin/xdebug status
Xdebug debug mode is disabled.

Actual Result

$ bin/xdebug status
Xdebug debug mode is disabled.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 5
  • Comments: 24 (5 by maintainers)

Most upvoted comments

@vy-shmal, as a momentary fix to that I change the compose to mount a volume to that php.ini file.

I create the file ./env/php.ini with the content of the original plus xdebug modifications:

memory_limit = 4G
max_execution_time = 1800
zlib.output_compression = On
cgi.fix_pathinfo = 0
date.timezone = UTC

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey=VSCODE

upload_max_filesize = 100M
post_max_size = 100M
max_input_vars = 10000

sendmail_path = "/usr/bin/msmtp -t"

And then in the compose.yaml file I add a volume…

services:
  app:
    build: images/nginx
    ports:
      - "80:8000"
      - "443:8443"
    volumes: &appvolumes
       - ~/.composer:/var/www/.composer:cached
       - ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
       - ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
+      - "./env/php.ini:/usr/local/etc/php/php.ini"
       - appdata:/var/www/html
       - sockdata:/sock
       - ssldata:/etc/nginx/certs
-    #extra_hosts: &appextrahosts
+    extra_hosts: &appextrahosts
       ## Selenium support, replace "magento.test" with URL of your site
       #- "magento.test:172.17.0.1"
+      - "host.docker.internal:host-gateway"
 
   phpfpm:
     image: markoshust/magento-php:8.1-fpm-1
     volumes: *appvolumes
     env_file: env/phpfpm.env
-    #extra_hosts: *appextrahosts
+    extra_hosts: *appextrahosts
 
   db:
     image: mariadb:10.4

...

First of all, i made the changes @MaskeZen recommended and after that, still doesnt working.

So after some tests i had to increment some this changes to get all working as expected.

System:

  • Ubuntu 20.04.6
  • PHPSTORM
  • Docker version 23.0.1, build a5ee5b1
  • Docker Compose version v2.17.2

Uncomment these lines in compose.yaml extra_hosts: - "host.docker.internal:host-gateway"

Add this entry on /etc/hosts 172.17.0.1 host.docker.internal

obs: To check the host you can paste this on your terminal docker network inspect bridge --format='{{(index .IPAM.Config 0).Gateway}}'

Change server path mapping on phpstorm servers to the “pub” directory, as the screenshot /var/www/html/pub image

Hope it helps someone!

I’ve been experiencing the same issue on Ubuntu 22.04.2 and, after some research, I’ve found that the issue seems to reside in the docker compose command being called in bin/docker-compose when running bin/start.

To fix the issue I’ve just updated the bin/docker-compose file as follows:

#!/bin/bash

if docker compose version > /dev/null 2>&1; then
-  DOCKER_COMPOSE="docker compose"
+  DOCKER_COMPOSE="docker-compose"
else
  DOCKER_COMPOSE="docker-compose"
fi

if [ "$1" == "--no-dev" ]; then
  ${DOCKER_COMPOSE} -f compose.yaml -f compose.healthcheck.yaml "${@:2}"
else
  ${DOCKER_COMPOSE} -f compose.yaml -f compose.healthcheck.yaml -f compose.dev.yaml "$@"
fi

I’m not sure why the docker compose is behaving differently than docker-compose, but might as well be a @docker internal issue.

Thanks @MaskeZen , you save my time!

Yea I really can’t see why that would be happening, unless the container is completely destroyed when it shuts down.

I don’t think the docker compose thing is any issue at all, as that line should properly return the exact version of docker compose you are running depending on the installed version.

That said, I’m not opposed to creating a new conf/php.ini file in the compose directory, as this would allow someone to easily edit the php.ini file right on the host. And since this file is mounted from the local filesystem, it should absolutely persist container restarts. If someone wants to test this out locally, and if it works, make a PR, I’ll take this in.

@xavierojeda try docker compose version to check that you have docker compose installed.

Forgot to attach the output for that one. Here it is: Screenshot from 2023-03-03 17-53-38

Confirm same behavior on manjaro linux with Docker Compose version 2.16.0

phpfpm container is recreated and xdebug is never enabled.

If I downgrade to Docker Compose version 2.14.2 then xdebug gets enabled as expected.

@MaskeZen Thanks. I have the same issue and this works with a small change like below. maybe help someone

- ~/.env/php.ini:/usr/local/etc/php/php.ini

@MaskeZen Yes it worked for me also, nice thank you.