markshust / docker-magento

Mark Shust's Docker Configuration for Magento
https://m.academy/courses/set-up-magento-2-development-environment-docker/
MIT License
2.51k stars 992 forks source link

can't enable xdebug, phpfpm container is recreated on restart. #866

Open MaskeZen opened 1 year ago

MaskeZen commented 1 year ago

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.

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.
vy-shmal commented 1 year ago

I have same problem also on Ubuntu. The container keeps recreating and the php.ini change is not persisting.

MaskeZen commented 1 year ago

@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

...
vy-shmal commented 1 year ago

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

markosege commented 1 year ago

@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

xavierojeda commented 1 year ago

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.

btantlinger commented 1 year ago

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 commented 1 year ago

@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

This depend on where you want to put your php.ini file.

markshust commented 1 year ago

@rangerz is it possible that bin/docker-compose script is returning a false positive on the first conditional check?

if docker compose version > /dev/null 2>&1; then
  DOCKER_COMPOSE="docker compose"
else
  DOCKER_COMPOSE="docker-compose"
fi
MaskeZen commented 1 year ago

Hello @markshust , no, this is ok, almost in my case.

bash test

markshust commented 1 year ago

@xavierojeda what is your output of the above?

xavierojeda commented 1 year ago

@xavierojeda what is your output of the above?

Hi @markshust. My output is the same as @MaskeZen's. Screenshot from 2023-03-03 17-46-06

MaskeZen commented 1 year ago

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

xavierojeda commented 1 year ago

@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

markshust commented 1 year ago

I have same problem also on Ubuntu. The container keeps recreating and the php.ini change is not persisting.

Going back to this... why is the container getting recreated? This doesn't make any sense. It should only start/stop, not get completely destroyed and then recreated.

rangerz commented 1 year ago

@rangerz is it possible that bin/docker-compose script is returning a false positive on the first conditional check?

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

I can't replicate

shinesoftware commented 1 year ago

Any update for this issue?

Everytime that I execute bin/xdebug toggle the xdebug is not enabled. @markshust I have the latest version of your package.

This works:

bin/root sed -i -e 's/^xdebug.mode = off/xdebug.mode = debug/g' /usr/local/etc/php/php.ini

but when I try to use bin/restart phpfpm I can see that the restart reset the php.ini to the default values:

xdebug.mode = off

Why this happens?

thanks

markshust commented 1 year ago

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.

ngtuan96lc commented 1 year ago

Thanks @MaskeZen , you save my time!

FXXDEV commented 1 year ago

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:

Uncomment these lines in compose.yaml ` extra_hosts:

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!

killvap commented 1 year ago

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 , it's really helps!

markosege commented 1 year ago

@killvap I have same issue and try to fix like your way but i am getting this error ERROR: The Compose file './compose.healthcheck.yaml' is invalid because: services.phpfpm.depends_on contains an invalid type, it should be an array services.app.depends_on contains an invalid type, it should be an array ERROR: The Compose file './compose.healthcheck.yaml' is invalid because: services.phpfpm.depends_on contains an invalid type, it should be an array services.app.depends_on contains an invalid type, it should be an array

lzyenjoy commented 1 year ago

I also encountered the same problem. If I just start the phpfpm service it works fine docker compose -f compose.yaml -f compose.healthcheck.yaml -f compose.dev.yaml start php-fpm

xdebug-bug

mts527 commented 1 year ago

Had the same issue on MacOS until I upgraded Docker Desktop to v4.20.1 and Docker Compose to v2.18.1.

victortodoran commented 8 months ago

Had the same issue on MacOS until I upgraded Docker Desktop to v4.20.1 and Docker Compose to v2.18.1.

I can confirm that upgrading Docker Desktop solved this issue for me as well.

Thank you @mts527 for taking the time to leave this comment.