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 3.0 with PHP 7.2, 7.3, 7.4 and 8.0 #769

Closed
llaville opened this issue Dec 18, 2020 · 20 comments · Fixed by #777
Closed

Xdebug 3.0 with PHP 7.2, 7.3, 7.4 and 8.0 #769

llaville opened this issue Dec 18, 2020 · 20 comments · Fixed by #777
Assignees

Comments

@llaville
Copy link
Contributor

llaville commented Dec 18, 2020

ISSUE TYPE

  • Feature request

SUMMARY

Migrate from old to new settings.

Goal

Xdebug v3 is a new major version that changed a lot especially on behavior and settings.
See the Xdebug Official Upgrade Guide

Following changes that were started with FR #746, Devilbox need again to be clean-up !

While I've started to introduced OPCache settings in a custom php.ini config file, I found that old settings from Xdebug v2 are still mentioned in default config files. Look at :

I suggest to remove these settings, and only used default provided by extension itself and other settings set in devilbox-php.ini-xdebug files

BTW, these files must be fixed as I've already said (#746 (comment))

I recommand to use these default settings :

xdebug.mode               = off
xdebug.start_with_request = yes
xdebug.client_port        = 9003
xdebug.idekey             = PHPSTORM
xdebug.log                = /var/log/php/xdebug.log

See Official Upgrade Guide

And especially to use mode = off by default, because even with xdebug 3.0.1 it consume more time and memory.

A little benchmark I've run on one of my CLI script took :

  • 100% 6 secs 251.5 MiB with xdebug.mode = off
  • 100% 1 min 301.5 MiB with xdebug.mode = trace
  • Fatal error with xdebug.mode = debug 100% 6 secs 251.5 MiB with xdebug_mode = debug and client_port = 9000
@llaville
Copy link
Contributor Author

One fixes on my previous report :

We MUST use xdebug.client_port = 9000 and not 9003 as recommanded in Xdebug Upgrade Guide.

Otherwise we will get an error like this one :

Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(

@llaville
Copy link
Contributor Author

Final settings suggestion could be :

xdebug.mode               = debug
xdebug.start_with_request = yes
xdebug.client_port        = 9000
xdebug.idekey             = PHPSTORM
xdebug.log                = /var/log/php/xdebug.log

@alikon
Copy link
Contributor

alikon commented Dec 18, 2020

i've made this change too (on a windows machine) and i confirm too that the port should be 9000 and not 9003

;xdebug.remote_host=xxx.xx.xx.xx
xdebug.client_host=xxx.xx.xx.xx

@cytopia
Copy link
Owner

cytopia commented Dec 19, 2020

@llaville For the PHP-FPM images I added the following sane defaults:

; Ensure to disable everything by default (be in sync with Xdebug v2)
xdebug.mode               = Off
xdebug.start_with_request = Off
xdebug.client_port        = 9000

devilbox/docker-php-fpm#191

@llaville
Copy link
Contributor Author

@cytopia sorry but i'm not agree with setting xdebug.start_with_request = Off. It does not means that something are started or stopped. See https://xdebug.org/docs/all_settings#start_with_request

I suggest to put xdebug.start_with_request = default

@cytopia cytopia self-assigned this Dec 19, 2020
@jonatanaxe
Copy link
Contributor

jonatanaxe commented Dec 29, 2020

Can I downgrade from xdebug to 2 in an easy way? @cytopia @llaville

I was unable to configure xdebug 3 to use in magento 2 PHP 7.2

@cytopia
Copy link
Owner

cytopia commented Dec 29, 2020

@jonatanaxe you could use any Docker image before this version: https://github.com/devilbox/docker-php-fpm/releases/tag/0.118

@SHJordanSLIM
Copy link

xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000
xdebug.idekey = PHPSTORM
xdebug.log = /var/log/php/xdebug.log

this worked for me on w10 plus setting defaults on PHPSTORM as on docs.

@wp4nuv
Copy link

wp4nuv commented Mar 11, 2021

Quick question, because this has also been an issue for me: When loaded the PHP image has fpm expecting connections to port 9000. Wouldn't that conflict with Xdebug 3? I use PHP Tools from Devsense, and they also state that debugging should be on port 9000. I was wondering if the PHP-FPM service could be "configurable", so to speak, to allow port changes when necessary.

What @llaville mentioned earlier, about the error of port 9003, I had that same issue and I have to ask, are you using WSL2 for the Linux backend? I found that if you install php on the linux wsl instance, so that, for example, Visual Studio Code can load any php extension that requires the language server, xdebug from Devilbox will actually attempt to make the connection that way. I found that an easy edit of the xdebug conf file to add the line xdebug.client_port = 9000 does the trick on the php installation at the WSL level.

@dereuromark
Copy link

xdebug.client_host=xxx.xx.xx.xx
Is there a quick way to find out what address to put here?
I guess we have to run this from within the shell? After ./shell.sh then.

@dereuromark
Copy link

ip route get 1 | sed 's/^.*src \([^ ]*\).*$/\1/;q' apparently gets the needed address

Once this is set, it worked for me.
I wonder if there is a more dynamic approach, as the above address is subject to change afaik.

@ParhamG
Copy link

ParhamG commented May 12, 2021

@dereuromark were you able to find a dynamic approach for this? I am running Docker on Windows with WSL2 backend and also running PhpStorm within WSL and would love to find a way to automate this.

@ahberg
Copy link
Contributor

ahberg commented May 17, 2021

@ParhamG I don't think you need to set xdebug.client_host if you use the suggestion settings and Xdebug helper Chomre plugin.

@Luc45
Copy link

Luc45 commented Jul 31, 2021

I had to point Xdebug to the docker gateway for it to work:

xdebug.mode               = debug
xdebug.start_with_request = yes
xdebug.client_host        = 172.16.238.1
xdebug.client_port        = 9003
xdebug.idekey             = PHPSTORM
xdebug.remote_log         = /var/log/php/xdebug.log

@antyblin
Copy link

antyblin commented Oct 6, 2021

I tried both 9000 and 9003 ports and got same error messages from Xdebug:

[Step Debug] Creating socket for '172.16.238.1:9000', poll success, but error: Operation now in progress (29).
[Step Debug] Could not connect to debugging client. Tried: 172.16.238.1:9000 (through xdebug.client_host/xdebug.client_port) :-(

IP address in the message is the same as in docker.for.lin.host.internal. I run Docker inside WSL2 and have recommended configuration for the Xdebug 3.
nc -vz 172.16.238.1 9000 from php container returns connection refused
but
nc -vz 172.21.144.1 9000 from wsl to windows host returns connection succeeded.

I'm absolutely devastated and desperate and would appreciate any help you can provide.

@Luc45
Copy link

Luc45 commented Oct 6, 2021

@antyblin Your docker gateway might be different. Try setting xdebug.client_host=host.docker.internal. If you are on Linux (Mayb WSL too), you might need to add this to the PHP service in docker-compose:

    extra_hosts:
      - "host.docker.internal:host-gateway"

Test again after docker-compose down && docker compose up -d

@antyblin
Copy link

antyblin commented Oct 6, 2021

@antyblin Your docker gateway might be different. Try setting xdebug.client_host=host.docker.internal. If you are on Linux (Mayb WSL too), you might need to add this to the PHP service in docker-compose:

    extra_hosts:
      - "host.docker.internal:host-gateway"

Test again after docker-compose down && docker compose up -d

Oh my god, it works! Thank you so much for the response! I've been struggling with this problem for a long time.
While I still don't understand how and why it works, I'm infinitely grateful to you!

@leakedby
Copy link

Add for bind & php services

extra_hosts:
      docker.for.lin.host.internal: 172.16.238.1
      docker.for.lin.localhost: 172.16.238.1
      host.docker.internal: host-gateway

xdebug.ini

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal
xdebug.client_post=9000
xdebug.idekey=PHPSTORM

Working for me :) Thank all.

@hielh
Copy link

hielh commented May 16, 2022

Hi,
All solutions didn't work for me. Following the activation of the rabbitmq and the activation of the firewall to make it work. My xdebug didn't work anymore.

After a day of research, I would have to deactivate the firewall.
Ubuntu 20
PHPSTORM

;Xdebug 3.X
xdebug.mode=debug
xdebug.client_port=9003
#xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.start_with_request=yes
xdebug.idekey=PHPSTORM
xdebug.show_error_trace = 1
xdebug.max_nesting_level=250
xdebug.var_display_max_depth=10
xdebug.connect_timeout_ms=300
xdebug.discover_client_host=1
xdebug.client_host=host.docker.internal

solution disable the firewall

sudo ufw disable

@cirolosapio-accenture
Copy link

hi all !
i'm trying to use xdebug with wsl+docker (no docker desktop) but i can't connect to wsl/windows host from the php container
i'm using a minimal php container with xdebug repro

i see that with devilbox this is possible so i ask:
what devilbox do to make this work?

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.