Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically trigger Xdebug when running PHP on CLI inside php-debug container #33

Closed
davidalger opened this issue Oct 29, 2019 · 6 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@davidalger
Copy link
Collaborator

The php CLI inside the php-debug container should trigger Xdebug automatically. Currently the only way to debug CLI commands (as opposed to HTTP requests which are routed to Xdebug automatically already) is to specify a couple settings to php:

warden env exec php-debug bash

php -d xdebug.remote_autostart=on -d xdebug.remote_host=host.docker.internal ...

At minimum remote_autostart should be set on CLI by default, and ideally the remote_host as well. That one will require a little work to get right on both macOS and Linux.

@davidalger davidalger added the enhancement New feature or request label Oct 29, 2019
@davidalger davidalger self-assigned this Oct 29, 2019
@davidalger
Copy link
Collaborator Author

davidalger commented Oct 29, 2019

10/18/19, 10:10 AM
I pass the values to the container environment variables via docker compose and -e.
e.g. docker-compose run -e PHP_IDE_CONFIG="serverName=$server_name" -e XDEBUG_CONFIG="remote_host=172.17.0.1" magento-cli "$@" now i just use this command instead of running with php flags
ref: https://twitter.com/petey_tweety/status/1185211571493994496

@wardenenv wardenenv deleted a comment from blackbooker Oct 29, 2019
@molotovbliss
Copy link

molotovbliss commented Nov 12, 2019

https://gist.github.com/molotovbliss/3eb18a2b0366d9b9e15647322641816d just to note for a possible way to get the container id along with passing the usual xdebug php params & script file to debug.


Created a PR with included help file and removal and clean-up. Version change may not be needed, FYI.

@wojtekn
Copy link
Contributor

wojtekn commented Dec 11, 2019

@davidalger this sounds as a great idea.

I'm not sure if I'm missing something, but wouldn't it be just about adding those two config directives in /etc/php.d/15-xdebug.ini in this container?

@davidalger davidalger added this to the Warden 0.2.0 milestone Jan 6, 2020
@davidalger
Copy link
Collaborator Author

Per a conversation I had with @wcrb15 the gateway IP of the warden network works as the remote_host on Linux systems. So in order to resolve this, it should be possible to look up and pass this gateway IP address as an extra_hosts parameter on Linux systems allowing docker.host.internal to resolve there as well as on macOS within the php-debug container. For the sake of not disrupting any existing functionality, the use of connect back for browser requests should remain untouched.

The gateway IP address can be looked up via the following similar to [what is done here](docker container inspect traefik --format '{{.NetworkSettings.Networks.warden.Gateway}}'):

docker container inspect traefik --format '{{.NetworkSettings.Networks.warden.Gateway}}'

davidalger pushed a commit to molotovbliss/warden that referenced this issue Jan 25, 2020
davidalger added a commit to davidalger/docker-images-warden that referenced this issue Jan 25, 2020
davidalger added a commit to davidalger/docker-images-warden that referenced this issue Jan 25, 2020
@davidalger
Copy link
Collaborator Author

Final solution has been to update PR #35 to adhere to the following:

  1. Introduces a new command warden debug; when this is run the user is launched into a shell similarly to when warden shell is run, but in this case the shell is opened by default within the php-debug container.

  2. When user is launched into a debug container, the env variable XDEBUG_REMOTE_HOST is passed in and conditionally set to either host.docker.internal on macOS and to the gateway IP of the warden network on Linux systems.

  3. The base images have been updated to add the following to /etc/php-cli.ini bringing it all together without any potential for disrupting already present and reliable in-browser debugging:

[php]
xdebug.remote_autostart=on
xdebug.remote_host=${XDEBUG_REMOTE_HOST}

Big shout out to @wcrb15 for helping ascertain what the remote host should be configured to on Linux systems and to @molotovbliss for getting the ball rolling with the idea of a special debug command.

davidalger added a commit that referenced this issue Jan 25, 2020
davidalger added a commit that referenced this issue Jan 25, 2020
@molotovbliss
Copy link

Big shout out to @wcrb15 for helping ascertain what the remote host should be configured to on Linux systems and to @molotovbliss for getting the ball rolling with the idea of a special debug command.

Thanks for the 😊 props, and same to @chapagain for updating my old gist with this feature! Cheers. 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants