Setting up debugging with XDebug 3 and WSL2

Tried the steps mentioned in this post and post. However, debugging continues to fail due to the following error: 

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


XDebug Config:

zend_extension=xdebug.so

xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_host=192.168.173.130
xdebug.remote_port=9000
xdebug.client_host=192.168.173.130
xdebug.client_port=9000
xdebug.log=/var/log/xdebug.log
#xdebug.discover_client_host=false
xdebug.idekey=PHPSTORM

 

This is a portion of the command executed by PHPStorm when debugging:

Unsure as to why the remote_host is passed as 127.0.0.1

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.173.130" "-d xdebug.client_host=192.168.173.130" "-d xdebug.remote_port=9000" -dxdebug.client_port=9000

 

And this is a portion of the command executed by PHPStorm when running a script/test:

php "-d xdebug.remote_host=192.168.173.130" "-d xdebug.client_host=192.168.173.130" "-d xdebug.remote_port=9000" -dxdebug.client_port=9000

In this case PHPStorm does not automatically pass 127.0.0.1 as remote_host's value and only the values setup in the XDebug options in IDE are passed.

Had uninstalled anti-virus and also disabled the firewall. However, debugging connection fails. Strangely nothing is written to xdebug logs.

System Info

PHPStorm Version: PhpStorm 2020.2.4
Build #PS-202.8194.11, built on November 25, 2020
Licensed to Nikhil Ranka
You have a perpetual fallback license for this version
Subscription is active until May 4, 2022
Runtime version: 11.0.9+11-b944.49 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0

Would be great if you could help in setting this up.

Thanks!

0

I've reproduced the problem with a failing CLI debugging. I'm running some checks now & if all confirms - I'll report it as a bug/usability problem and let you know. 

0

Submitted as https://youtrack.jetbrains.com/issue/WI-65350 - feel free to vote for it in order to get notified about its updates.

0
Avatar
Permanently deleted user

I have Windows 11 + WSL2 with Ubuntu.

My development file are located on ubuntu server.

My configuration:
zend_extension=xdebug.so
xdebug.idekey = PHPSTORM
xdebug.mode = debug
; xdebug.discover_client_host = true
xdebub.remote_enable = 1
xdebug.client_port = 9003
xdebug.client_host = 192.168.1.190
xdebug.remote_port = 9003
xdebug.remote_host = 192.168.1.190
xdebug.log = /var/log/xdebug.log


0
Avatar
Permanently deleted user

after add folder mapping it started working

0
Avatar
Permanently deleted user

It stop working.

My xDebug configuration:
zend_extension=xdebug.so
xdebug.idekey = PHPSTORM
xdebug.mode = debug
; xdebug.discover_client_host = true
xdebub.remote_enable = 1
xdebug.client_port = 9003
xdebug.client_host = 192.168.1.190
xdebug.remote_port = 9003
xdebug.remote_host = 192.168.1.190
xdebug.log = /var/log/xdebug.log


Xdebug log:

0
Avatar
Permanently deleted user

The problem was with Windows Deffender firewall which blocks my connection.
I setup this like here:

0

Since this link appeared on the first page of search results during my investigation into configuring Xdebug with WSL, I want to share the details of how I found a solution to resolve the problem for myself.

Preconditions:
- Installed WSL with Debian
- PHP 8.4, Xdebug 3.4.7, 
- default configs everywhere (PhpStorm, xdebug)
- PHP interpreter in PhpStorm configured to the WSL Debian
- Error “Cannot start debugger session with 'Xdebug 3.4.7'” from PhpStorm while trying to run PHP script on debug mode

```
[\\wsl$\Debian]:/usr/bin/php -dxdebug.mode=debug -dxdebug.client_port=9003 -dxdebug.client_host=127.0.0.1 /mnt/d/development/php/example/src/index.php
Xdebug: [Step Debug] Could not connect to debugging client. Tried: 127.0.0.1:9003 (through xdebug.client_host/xdebug.client_port).
hello worldbar
Process finished with exit code 0
```

The first problem: PhpStorm passes “127.0.0.1” to the command instead of the IP of the Windows host machine. 
Note: in my case, the IP of the host machine (found by calling the “ipconfig”) was “172.20.96.1”, but it's not necessary for the solution

I found that I can disable passing “-dxdebug.client_*” parameters by the PhpStorm with disabling flag `Pass require configuration options through command line (still need to enable debug extension manually)` from `Settings > PHP > Debug > Settings`.

By that change, I can assume, that Xdebug's configuration will be used. But, I need to enable Xdebug “debug” mode explicitly now. And Xdebug defaults didn't work for WSL either, so it's not a finish yet.

(No error in the script output, but there is no started debug session in PhpStorm)
```
[\\wsl$\Debian]:/usr/bin/php /mnt/d/development/php/example/src/index.php
hello worldbar
Process finished with exit code 0
```

I changed two xdebug configurations: `xdebug.mode`, `xdebug.client_host`

(/etc/php/8.4/mods-available/xdebug.ini)
```
xdebug.mode=debug
xdebug.client_host=xdebug://gateway
```

After that change, I got successfully working step debugging process in PhpStorm

```
[\\wsl$\Debian]:/usr/bin/php /mnt/d/development/php/example/src/index.php
###### by the author — process waiting for the continue from IDE #########
```


 

Refs:
1. https://stackoverflow.com/a/78923209
2. https://xdebug.org/docs/step_debug#client_host 
 

1

请先登录再写评论。