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
-D
java.net.preferIPv6Addresses=true
Is there any manual how to configure PHPStorm for WSL2 debugging ?
Please sign in to leave a comment.
I would suggest adding the "xdebug.log" directive and check the log file afterwards. By the way, do you debug a web application, right?
Yes, I'm trying to debug web application. Setting xdebug.log I get the following messages:
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
Thanks guys for your help!
Adding xdebug.client_host with IP of my PC (not wsl instance) has resolved my issue!
Cool!
Thanks for the update and have a productive new week.
Vasiliy Yur
Add the below config. Restarted PHP FPM. Despite that, the following error is shown in PHPStorm:
XDebug Config:
Nothing is printed in the logs.
This is a portion of the command executed by PHPStorm:
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
Can you share the steps to get this working?
Thanks!
Vasiliy Yur
Created a new post here: https://intellij-support.jetbrains.com/hc/en-us/community/posts/4406842719378-Setting-up-debugging-with-XDebug-3-and-WSL2
replied in a new post
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.
Replied there.