Xdebug3 + WSL2

Hi! Could someone help me out how to properly setup PHPStorm debug for WSL2 and Xdebug3 ?

Ubuntu 20.04 is installed on WSL2, PHP7.4 xdebug.ini has the following configuration:

zend_extension=xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes

This config works fine with VisualStudio Code but with PHPStorm when I set a breakpoint and start listening nothing happens.

I have a suspicion that VSCode listens for IPV6 incoming debug connection but PHPStorm only IPV4. Can it be a problem ?

How to force PHPStorm to listen to IPV6 connections ? Setting the java options doesn't help:

-Djava.net.preferIPv4Stack=false
-Djava.net.preferIPv6Addresses=true

Is there any manual how to configure PHPStorm for WSL2 debugging ?

 

1
10 comments

I would suggest adding the "xdebug.log" directive and check the log file afterwards. By the way, do you debug a web application, right?

0

Yes, I'm trying to debug web application. Setting xdebug.log I get the following messages:

[3010] Log opened at 2021-04-01 18:31:41.957959
[3010] [Step Debug] INFO: Connecting to configured address/port: localhost:9003.
[3010] [Step Debug] WARN: Creating socket for 'localhost:9003', poll success, but error: Operation now in progress (29).
[3010] [Step Debug] ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
[3010] [Step Debug] INFO: Connecting to configured address/port: localhost:9003.
[3010] [Step Debug] WARN: Creating socket for 'localhost:9003', poll success, but error: Operation now in progress (29).
[3010] [Step Debug] ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
[3010] [Step Debug] INFO: Connecting to configured address/port: localhost:9003.
[3010] [Step Debug] WARN: Creating socket for 'localhost:9003', poll success, but error: Operation now in progress (29).
[3010] [Step Debug] ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port) :-(
[3010] Log closed at 2021-04-01 18:31:41.985802

0

Basically, XDebug should connect to the <ide_machine>:9003 which is generally not the "localhost" in the case of WSL2

So, you may want to hardcode your host machine IP/name with the "xdebug.client_host=" directive. Otherwise, you may enable the "xdebug.discover_client_host" option for XDebug to detect the HTTP client address automatically.

A little bit more about these options:
https://xdebug.org/docs/all_settings#discover_client_host
https://xdebug.org/docs/all_settings#client_host

0

Thanks guys for your help!

Adding xdebug.client_host with IP of my PC (not wsl instance) has resolved my issue!

 

0

Cool!

Thanks for the update and have a productive new week.

0

Vasiliy Yur

Add the below config. Restarted PHP FPM. Despite that, the following error is shown in PHPStorm:

Connection was not established. Cannot start debugger session with 'Xdebug 3.0.4


XDebug Config:

xdebug.remote_host=192.168.29.249
xdebug.client_host=192.168.29.249
xdebug.client_port=9000
xdebug.log="/var/log/xdebug.log"

Nothing is printed in the logs.

This is a portion of the command executed by PHPStorm:

php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1

Unsure as to why the host is passed as 127.0.0.1

Passed additional params via config option. The connection cannot be established yet

php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 "-d xdebug.remote_host=192.168.29.249"

Can you share the steps to get this working?

Thanks!

0

replied in a new post

1

Thanks, Dmitry Tronin for the detailed response. Got engaged in other activities. The steps you mentioned worked - irrespective of the internet/VPN connection.

Wanted clarity on a couple of items:

1. On every restart the IP of WSL2 changes. Wrote a temporary bash script to update the IP in XDebug. Any other approaches to handle this?

2. For the first debug attempt after a restart the following error is thrown. Any ideas on resolving this?

PS: Having this in the documentation website would certainly help many others.

0

Please sign in to leave a comment.