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 Documentation #575

Open
metal450 opened this issue May 6, 2019 · 25 comments
Open

xDebug Documentation #575

metal450 opened this issue May 6, 2019 · 25 comments

Comments

@metal450
Copy link

metal450 commented May 6, 2019

ISSUE TYPE

  • Documentation

SUMMARY

Ambiguity with xDebug on Docker Toolbox setup

Goal

To get xDebug working properly on Docker Toolbox, & clarify the docs to make it easier for others.


I've been struggling for several hours, still unsuccessfully, to get xDebug working on Docker Toolbox, based on the docs here: https://devilbox.readthedocs.io/en/latest/intermediate/configure-php-xdebug/toolbox/vscode.html.

  1. The first confusion was with the 'Prerequisites': it mentions that you need to forward host port 9000, but then gives two different links. Which should we use? I believe the answer is that you can choose either one (based on https://github.com/cytopia/devilbox/blob/master/docs/advanced/connect-to-host-os.rst#id6). That clarification would help.

  2. Since I'm on Windows & don't have an SSH server running, I went with https://devilbox.readthedocs.io/en/latest/howto/docker-toolbox/ssh-port-forward-on-host-to-docker-toolbox.html. I launched the QuickStart Terminal & entered the example command - after which it prompts for the "docker" user's password. What should we use? After more digging around, I found that you should use the key like: ssh -R 9000:127.0.0.1:9000 docker@192.168.99.100 -i .docker/machine/machines/default/id_rsa. Having that in the example docs would've saved time.

  3. As for actually getting it working...it still isn't, so there must be something I'm still missing/misunderstanding from the instructions. As an initial proof-of-concept though, I CAN get xdebug it working (hitting breakpoints) with php.ini like:

xdebug.default_enable = 1
xdebug.remote_enable = 1
xdebug.remote_connect_back=0
xdebug.remote_log=/var/log/php/xdebug.log
xdebug.remote_host=(the actual IP of my host machine, i.e. 192.168.1.xx)

This proves that xdebug is fundamentally on, path mapping is correct, there's no firewall in the way, etc. However, when I change xdebug.remote_host=docker.for.lin.host.internal, the logs always show:

I: Connecting to configured address/port: docker.for.lin.host.internal:9000.
E: Could not connect to client. :-(

This makes me think it's still something related to port forwarding. I also tried going into the VirtualBox machine's settings->Network->Adapter 1 (nat)->Advanced->Port Forwarding & added port 9000, but it didn't help. I tried some other setups found by digging around elsewhere - i.e. using IP 10.0.2.2 instead of docker.for.lin.host.internal - but nothing seemed to work.

Obviously hardcoding my host PC's current IP isn't a long-term solution (it's a laptop that moves around & gets different IPs), but this is where I remain stuck. It works if I give php the direct IP...but not if I use docker.for.lin.host.internal.

@FireEmerald
Copy link

Your are not the only person who encountered exactly the same issue. Xdebug and Docker is in my eyes really a pain, because of the xdebug.remote_host. If your setup isn't running it's 99% chance that you choose the wrong ip. Ended also hardcoding it.

@cytopia
Copy link
Owner

cytopia commented May 8, 2019

I will draft an PR on this with the information I currently have. Please be noted that I do not have a Windows machine to test with, so I will rely on the information provided.

Hope we can get this right and well documented this time.

@metal450
Copy link
Author

metal450 commented May 8, 2019

Great, thanks - looking forward to hopefully getting it working :)

@stale
Copy link

stale bot commented Jul 7, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the issue:stale This issue has become stale and is marked for auto-close label Jul 7, 2019
@metal450
Copy link
Author

metal450 commented Jul 9, 2019

Bumping to keep the issue from closing. Still unable to configure xdebug without hardcoding my PC's actual IP address.

@stale stale bot removed the issue:stale This issue has become stale and is marked for auto-close label Jul 9, 2019
@stale
Copy link

stale bot commented Sep 7, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the issue:stale This issue has become stale and is marked for auto-close label Sep 7, 2019
@metal450
Copy link
Author

metal450 commented Sep 7, 2019

...Still no solution (4mo later), so no, this should not be marked as stale.

@stale stale bot removed the issue:stale This issue has become stale and is marked for auto-close label Sep 7, 2019
@stale
Copy link

stale bot commented Nov 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the issue:stale This issue has become stale and is marked for auto-close label Nov 6, 2019
@metal450
Copy link
Author

metal450 commented Nov 6, 2019

...Still no solution (6mo later), so no, this should not be marked as stale.

@stale stale bot removed the issue:stale This issue has become stale and is marked for auto-close label Nov 6, 2019
@cytopia cytopia self-assigned this Dec 28, 2019
@alikon
Copy link
Contributor

alikon commented Jan 1, 2020

i've experienced a similar issue,
the only way i've got xdebug working, is putting the local ip in to the my overriden "xdebug.ini"

@pierregermain
Copy link

With xdebug 3 the documentation really needs a refresh. Would like to help but I am still not able to configure it on linux.

@pierregermain
Copy link

Has somebody bean able to configure devilbox using xdebug 3 using PphStorm on linux ?

@ARehmanMahi
Copy link

ARehmanMahi commented Aug 26, 2021

Solution for PHPStorm and Linux (Ubuntu 20.04)

After 6 hours of tries I finally manged to run xDebug.
All CREDIT GOES TO #628 (comment) helpful soution

Config:
Devilbox v1.9.2 latest as of today
apache2.4
php7.3

Step 1

cd devilbox/cfg/php-ini-7.3
touch xdebug.ini
vim xdebug.ini

Copy the following content into newly created file, its copied from devilbox-php.ini-xdebug file in the same folder

xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.remote_handler = dbgp
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
xdebug.remote_log = /var/log/php/xdebug.log

; This is the REQUIRED extra bit PHPStorm hints you to add this in php.ini
xdebug.client_host = 172.16.238.1

Step 2

Ensure DBGp proxy settings are configured in PHPStorm
Note the Host IP
image

Basically the devilbox docs says to put 0.0.0.0 in the host, you actually have to put the external_host IP of php image
image

Step 3

image

Step 4

image

That's It, Happy debugging.

You can add browser specific debuger plugin as well (Optional)
link: https://www.jetbrains.com/help/phpstorm/browser-debugging-extensions.html

@masiorama
Copy link

@ARehmanMahi hello, I installed PHPStorm and tried to follow your suggestions, but still I cannot make it work... maybe I am missing something trivial, but still cannot figure it out.

xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.remote_handler = dbgp
xdebug.client_host = 172.16.238.1
xdebug.remote_port = 9000
xdebug.idekey = PHPSTORM
xdebug.remote_log = /var/log/php/xdebug.log

dbgp

validate

server

Once I access my project on the browser via https://mytest.loc no breakpoint get triggered.

@ARehmanMahi
Copy link

ARehmanMahi commented Oct 31, 2021

@masiorama xdebug.ini must contain xdebug.client_host = 172.16.238.1
I don't see that in your provided gist.

Also in my answer step 3, make sure you have enabled start listing, the green telephone icon.

P.S. I've ubuntu install locally, and all the docker stuff was experimental stuff for me, and it turned out to be more hassle then improvement, I Installed LAMP stack and am very happy now, I also do manage my own VPN for testing and stuff with clean lamp stack, works perfect for me. Like PHPStorm does't support remote NodeJS the way it does php/xdebug. I needed that for my JS validation plugin. The mainter of this repo rarely reply and is only contributor so its kind of a dead project for me. End of rant. Good luck

@masiorama
Copy link

Hi @ARehmanMahi, actually the ip is there... Or you mean something different?

I also triggered the Start Listening button.

You mean that you are using a LAMP stack instead of the devilbox env?

Thanks!

@ARehmanMahi
Copy link

ARehmanMahi commented Oct 31, 2021

@masiorama yeah, my bad, you have the IP there, by the way I noticed you are using the vwsl linux on windows. I'm actually on ubuntu, and Yes I'm using lamp stack instead of docker. Its way easier and customiseable than devilbox once set correctly.

P.s. On windows Laragon is The Best I've had used. (PHP, wordpress, laravel and more)

@masiorama
Copy link

@ARehmanMahi exactly, I'm on wsl2 (ubuntu + docker + devilbox).
Thanks for the infos, but I'd like to stick to devilbox since I use it from the beginning (I believe 4 years) and it really suits my flexibility needs... If I could solve this debug issue it would be perfect for me.

@masiorama
Copy link

I managed to make it work with Win10 + WSL2 (Ubuntu 20.04): inside WSL2 I installed docker, docker-compose and devilbox. I can debug from VSCODE installed on Win10.

@geeksupport1
Copy link

geeksupport1 commented Feb 26, 2022

I managed to make it work with Win10 + WSL2 (Ubuntu 20.04): inside WSL2 I installed docker, docker-compose and devilbox. I can debug from VSCODE installed on Win10.

Hi @masiorama ,

I am trying to do the same.

Can you please provide a guide on how you did it?

Thanks in advance.

@masiorama
Copy link

Hi @geeksupport1, sure, I will help you if I can.
What did you accomplished so far? Where are you stuck at the moment?

I wrote a complete guide in 6 steps/pages on my website, but it is in italian.
Here you can find the step related to xDebug: https://www.masiorama.it/news/come-preparare-un-ambiente-di-sviluppo-php-completo-su-windows-10-wsl2-docker-devilbox-xdebug-step-5

Let me know if you can follow it.

@juicytoo
Copy link

Hi @masiorama,

Thanks for the link.

I think devilbox is great if you have a linux machine,

But on WSL2, as the founder does not use WSL2 there will continue to be problems.

After trying it for 2 days, I gave up.

I followed
https://docs.microsoft.com/en-us/shows/beginners-series-to-dev-containers/[https://docs.microsoft.com/en-us/shows/beginners-series-to-dev-containers/](https://docs.microsoft.com/en-us/shows/beginners-series-to-dev-containers/)
and got it working for WSL2, docker, VScode within 1 hour.

The VSCode tooling does all the config for you and a directory and creates 2 files to make it work:
.devcontainer/

  • Dockerfile
  • devcontainer.json

Things are changing fast.

@masiorama
Copy link

Just to mention, I work with xdebug on wsl2+devilbox without issues.

@juicytoo
Copy link

juicytoo commented Jan 5, 2023 via email

@cytopia
Copy link
Owner

cytopia commented Jan 5, 2023

Let's continue in the aggregated thread here: #946

Repository owner locked and limited conversation to collaborators Jan 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants