Setting up Xdebug 3 in WSL2 and docker with VSCode

I am trying to setup Xdebug 3 in my development environment for OpenEMR. I am using WSL2 with docker and have configured all the settings accordingly. This is a snapshot of my xdebug.ini file:

zend_extension=xdebug
xdebug.discover_client_host=true
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.remote_enable=1
xdebug.log_level=7
xdebug.client_host=host.docker.internal
xdebug.log=/tmp/xdebug.log
xdebug.idekey=VSCODE
~

I have configured it and yet when I put in a breakpoint, the code executes, but it never goes into the IDE for the breakpoint. The Listen to Xdebug just stays there. I went through the logs, and this is what I found:

[23] [Step Debug] INFO: Checking for client discovery headers: 'HTTP_X_FORWARDED_FOR,REMOTE_ADDR'.                                                          
[23] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'. 
[23] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.                                                                                                      [23] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.18.0.1:9003.                                                          
[23] [Step Debug] WARN: Creating socket for '172.18.0.1:9003', poll success, but error: Operation in progress (29).                                         
[23] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9003. 
[23] [Step Debug] ERR: Time-out connecting to debugging client, waited: 200 ms. Tried: 172.18.0.1:9003 (from REMOTE_ADDR HTTP header), host.docker.internal:
[23] Log closed at 2023-10-03 11:15:07.346849

I have configured the chrome extension as well and when I try it, it doesn’t work. Any help would be much appreciated.

hi @blazinp , you can explore how the easy dev docker is setup for xdebug.

I have set it up accordingly, but there seems to be an issue with WSL2. It still says the same error as above.

Is there a way to fix this?

does this post help?

Nope, still getting same error.

[23] [Step Debug] INFO: Checking for client discovery headers: 'HTTP_X_FORWARDED_FOR,REMOTE_ADDR'.
[23] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[23] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.                                                                  [23] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.18.0.1:9003.                      [23] [Step Debug] WARN: Creating socket for '172.18.0.1:9003', poll success, but error: Operation in progress (29).
[23] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured addre[23] [Step Debug] ERR: Time-out connecting to debugging client, waited: 200 ms. Tried: 172.18.0.1:9003 (from REMOTE_ADDR[23] Log closed at 2023-10-05 16:44:23.313220

hi @blazinp , this is the easy dev snippet of php.ini

; start xdebug configuration
zend_extension=/usr/lib/php82/modules/xdebug.so
xdebug.output_dir=/tmp
xdebug.start_with_request=trigger
xdebug.remote_handler=dbgp
xdebug.log=/tmp/xdebug.log
xdebug.discover_client_host=1
xdebug.mode=debug,profile
xdebug.profiler_output_name=cachegrind.out.%s
xdebug.client_port=9003
xdebug.client_host=host.docker.internal
; end xdebug configuration

Yep this is the same in php.ini . I added extra_hosts in docker-compose.yml as well.

Still the same issue.

This is a snapshot of the xdebug.ini file

zend_extension=xdebug.so
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_port=9003
xdebug.remote_connect_back=1
xdebug.idekey=VSCODE
xdebug.mode=debug
zend_extension=xdebug.so
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal

Still facing the same issue. Is there no way to setup Xdebug for WSL2 and docker?

maybe @robert.down can help since he’s using that setup?