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

XDEBUG on Windows not working #209

Closed
3 tasks
sonicviz opened this issue Mar 13, 2018 · 16 comments · Fixed by #531
Closed
3 tasks

XDEBUG on Windows not working #209

sonicviz opened this issue Mar 13, 2018 · 16 comments · Fixed by #531

Comments

@sonicviz
Copy link

sonicviz commented Mar 13, 2018

  • Which operating system are you at (Linux, OSX or Windows)
    Windows 10 Pro 1709 16299.248
  • docker version
    Version 17.12.0-ce-win47 (15139)
  • docker-compose version
    1.18.0

I'm trying Devilbox as an alternative to other Docker Wordpress setups I've been using.
I'm managed to get it working up to the point of a WordPress install, all hooked up and working fine.
It's very fast, much better than 10ups Docker for WP.

However, I can't get XDEBUG from VSCode to attach. Without debug, it's pretty much useless.
I'm pretty certain I need to use the vEthernet Default Switch IP address, and Code is definitely listening on port 9000 when I enter debug mode. But it doesn't hit breakpoints at all, so it's obviously not connecting.

Could it be the path mappings are wrong in the Launch Config?
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "pathMappings": {
            "/shared/httpd/wordpress1": "${workspaceRoot}/data/www/wordpress1/htdocs"
        }
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000
    }
]

}

Any tips?

@cytopia
Copy link
Owner

cytopia commented Mar 14, 2018

"pathMappings": {
            "/shared/httpd/wordpress1": "${workspaceRoot}/data/www/wordpress1/htdocs"
        }

From an initial view, the paths don't match. Shouldn't the left be "/shared/httpd/wordpress1/htdocs".

Also here is some other information I just found: https://stackoverflow.com/questions/37478387/how-to-setup-xdebug-and-phpstorm-with-docker-for-windows-beta

Are you using native Docker or Toolbox for windows?.

Either way I am happy to get this sorted with u as i am currently writing the documentation for xdebug and windows is still the missing part.

@cytopia cytopia self-assigned this Mar 14, 2018
@cytopia
Copy link
Owner

cytopia commented Mar 14, 2018

What you should do is:

  1. Use the new php images from this PR: REL-0.13: New PHP Container #203

    • This PR contains description for how to check it out
    • It will be merged soon, but is different from current master (which will be deprecated)
  2. in the new PR, there is no .env setting for xdebug, you need to add this to php.ini yourself.

    • go to cfg/php-fpm-5.6/ (or any other version u require)
    • create a file xdebug.ini with the following content:
xdebug.remote_connect_back=0
xdebug.remote_host=192.168.246.1 

But wait

You need to change the IP address and use your own.

How to get your IP address:

In a Windows command-line, run “ipconfig” and look for the IP4 address in “DockerNAT” entry. 192.168.246.1 in my case

Let me know if this works

Edit:

Credits to this post: https://forums.docker.com/t/solved-how-to-setup-xdebug-and-phpstorm/13641/23

@sonicviz
Copy link
Author

I've had a similar issue in the past with 10UP Docker and solved it as outlined here 10up/wp-local-docker#53 but it recently broke again. Pita to fix.
Which is why I'm trying Devilbox.

I'll try out the above and see if I can get it working. ty.

@sonicviz
Copy link
Author

sonicviz commented Mar 15, 2018

I got XDebug working with the PR: #203 but with some modification to your instructions.
I successfully got a breakpoint hit in a phpinfo.php test file in the root of htdocs, which is my initial Xdebug test.

Here's the configuration, assuming you are using PR: #203
xdebug.ini in E:\Source Control\Docker\devilbox1\cfg\php-fpm-7.1\ (or whatever your path is)

xdebug.remote_enable = 1
xdebug.remote_connect_back=0
xdebug.remote_autostart = 1
xdebug.remote_host=192.x.y.z

Note: xdebug.remote_host should be the IP Address of the Hyper-V Virtual Ethernet Adaptor, not DockerNat IP address. You can see this in Win 10 Task Manager performance tab or use ipconfig
There's 4 of these on my system, the one that works for me has
Adapter Name: vEthernet (Default Switch) NOT the vEthernet (DockerNAT) IP.

Also Note: this is different from what they say here https://forums.docker.com/t/solved-how-to-setup-xdebug-and-phpstorm/13641/23 but it's what works on my system using Native Docker for Windows

VSCode Launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

    {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9000,
        "pathMappings": {
            "/shared/httpd/wordpress1/htdocs": "${workspaceRoot}/data/www/wordpress1/htdocs"
        }
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9000
    }
]

}

@cytopia
Copy link
Owner

cytopia commented Mar 15, 2018

Great, I will add it to the documentation. New docs are going to be around here, but are still under development: http://devilbox.readthedocs.io/en/documentation/

@cytopia cytopia closed this as completed Mar 15, 2018
@cytopia
Copy link
Owner

cytopia commented Jul 26, 2018

Generalized Xdebug documentation now available: https://devilbox.readthedocs.io/en/latest/intermediate/configure-php-xdebug.html

@erythro
Copy link

erythro commented Mar 5, 2019

Note: xdebug.remote_host should be the IP Address of the Hyper-V Virtual Ethernet Adaptor, not DockerNat IP address. You can see this in Win 10 Task Manager performance tab or use ipconfig
There's 4 of these on my system, the one that works for me has
Adapter Name: vEthernet (Default Switch) NOT the vEthernet (DockerNAT) IP.

Also Note: this is different from what they say here https://forums.docker.com/t/solved-how-to-setup-xdebug-and-phpstorm/13641/23 but it's what works on my system using Native Docker for Windows

Thank you so much, this point was ultimately was did it for me. I've been banging my head against this all afternoon, and using that IP isn't documented anywhere but your comment as far as I can tell.

@cytopia
Copy link
Owner

cytopia commented Mar 5, 2019

@erythro thanks for pointing this out. I will reopen this issue until the documentation is updated accordingly.
Can you supply a screen shot of the Hypver-V Virtual Ethernet Adaptor and the command how to display this on windows.

@cytopia cytopia reopened this Mar 5, 2019
@cytopia
Copy link
Owner

cytopia commented Mar 6, 2019

@erythro could you also check to see if the following php.ini setting works equally well?

xdebug.remote_enable = 1
xdebug.remote_connect_back=0
xdebug.remote_autostart = 1
xdebug.remote_host = host.docker.internal

@erythro
Copy link

erythro commented Mar 8, 2019

Hi @cytopia thanks, I'll give a more full explanation here, though I'm a bit out of my depth. I slightly misunderstood the comment I quoted.

I suspect the problem might have been related to some messing around with virtualisation I did ages ago with the hyper-v manager. I wanted to create an ubuntu virtual machine, but followed a guide, and part of that guide was creating a virtual switch so my virtual machine could have access to the internet (iirc).

Here's an anonymised screenshot of the output of ipconfig:

image

The thing that finally worked for me was setting the remote_host to 192.168.0.12, the value from "New Virtual Switch". So is it possible I set up that virtual switch in such a way that it interfered with the Devilbox and/or Docker?

Here's a screenshot of the configuration of the switch:

image

So the settings you asked me to use didn't work for me, but I assume that's because I wasn't actually using vEthernet (Default Switch).

@sonicviz
Copy link
Author

sonicviz commented Mar 15, 2019

This is broken for me again now and I can no longer get XDebug to work.

Update: Fixed by doing the following

using the vEthernet (Default Switch) IP address as outlined previously
in Launch.json
"/shared/httpd/phptest/htdocs": "${workspaceRoot}/data/www/phptest/htdocs" NOT workspaceFolder as you have in the docs

@lj3lj3
Copy link

lj3lj3 commented Mar 22, 2019

Using IP address of vEthernet (Default Switch) instead of DockerNAT works for me on windows with docker desktop!

@cytopia
Copy link
Owner

cytopia commented Mar 24, 2019

I have rewritten the documentation and hope it does no present what actually needs to be done in Release v1.0.1

https://github.com/cytopia/devilbox/releases/tag/v1.0.1

@sonicviz
Copy link
Author

sonicviz commented Apr 2, 2019

It's suddenly no longer working for again.

The instructions also seem different again as well.

eg: now in Launch.Json you say
"/shared/httpd/mytest/htdocs": "${workspaceRoot}/htdocs"

but it used to be

            "/shared/httpd/mytest/htdocs": "${workspaceRoot}/data/www/mytest/htdocs" 

Xdbug is set up correctly, it's listening on 9000 as verified in Windows Resource monitor but it won't jump into a breakpoint doing a simple test with phpinfo.

I just pulled the latest Devilbox as well. This is really frustrating as Xdebug is a critical need atm.

@sonicviz
Copy link
Author

sonicviz commented Apr 3, 2019

Update: To test if it was a problem with my machine and/or Docker I've installed https://github.com/10up/wp-local-docker-v2 and successfully connected to XDebug

I still can't get Devilbox Xdebug working again so sadly will have to switch to 10up, as XDebug is essential to me.
I can't understand why Devilbox is so twitchy here though, It works, then it doesn't work and I literally spend hours trying to figure out why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants