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

Get XDebug 3 working in Docker #936

Merged
merged 2 commits into from
May 4, 2021
Merged

Get XDebug 3 working in Docker #936

merged 2 commits into from
May 4, 2021

Conversation

megahirt
Copy link
Collaborator

@megahirt megahirt commented May 4, 2021

These changes enable XDebug PHP debugging using VSCode + PHP Debug extension.

I used a number of instructions/tidbits from the internet to figure out how to get this working. Most of the documentation on the internet refers to XDebug 2 configurations, however we are running XDebug v3 which has different configuration options.

In addition, for this to work, the XDebug program running inside Docker needs to connect to VSCode on the host, port 9003. Normally services running inside Docker don't need the ability to connect to services running on the host, however XDebug is a different kind of animal and needs this ability.

I added the extra_hosts in docker-compose to make this possible. This requires Docker v20.10 or later to use the special host.docker.internal hostname.

Some additional notes on debugging PHP using VSCode and XDebug:

  • Because PHP composer dependencies only exist inside the docker container and not in your source tree, XDebug cannot step into vendor/composer dependencies unless you also download dependencies on your host. This is an extra step that might not be practical. If you get a VSCode error stating that it cannot find a file, check to make sure that it is not in the vendor folder.

VSCode allows you to break on 'everything'. I suggest turning this off so that the debugger doesn't break inside composer dependencies by default.

XDebug can probably safely be included in the production build since it defaults to "off". If we create a separate app build for production, then XDebug can be omitted entirely.


This change is Reviewable

@longrunningprocess
Copy link
Contributor

XDebug can probably safely be included in the production build since it defaults to "off". If we create a separate app build for production, then XDebug can be omitted entirely.

I'm guessing we'll have a separate image for this build since we don't wait in there either and we'll probably want a different php.ini as well, not sure what else at this point but I hope to chat through it a little at tonight's stand-up.

These changes enable XDebug PHP debugging using VSCode + PHP Debug extension.

I used a number of instructions/tidbits from the internet to figure out how to get this working.  Most of the documentation on the internet refers to XDebug 2 configurations, however we are running XDebug v3 which has different configuration options.

In addition, for this to work, the XDebug programming running inside Docker needs to connect to VSCode on the host on port 9003.  Normally services running inside Docker don't need the ability to connect to services running on the host however XDebug is a different kind of animal and needs this ability.

I added the `extra_hosts` in docker-compose to make this possible.  This requires Docker v20.10 or later to use the special `host.docker.internal`

Some additional notes on debugging PHP using VSCode and XDebug:

- Because PHP composer dependencies only exist inside the docker container and not in your source tree, XDebug cannot step into vendor/composer dependencies (unless you decide to download dependencies on your host).  If you get a VSCode error stating that it cannot find a file, check to make sure that it is not in the vendor folder.

VSCode allows you to break on 'everything'.  I suggest turning this off so that the debugger doesn't break inside composer dependencies by default.
@longrunningprocess
Copy link
Contributor

FYI @megahirt , there was a merge conflict that I resolved locally and force pushed up.

@longrunningprocess longrunningprocess merged commit c5ea2c4 into master May 4, 2021
@longrunningprocess longrunningprocess deleted the feature/xdebug branch May 4, 2021 18:22
@longrunningprocess longrunningprocess restored the feature/xdebug branch May 4, 2021 18:22
@longrunningprocess longrunningprocess deleted the feature/xdebug branch May 4, 2021 18:23
@megahirt megahirt added this to Reviewer approved in Infrastructure 2021 May 5, 2021
@megahirt megahirt moved this from Reviewer approved to Done in Infrastructure 2021 May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants