Opened 8 months ago
Closed 4 months ago
#63979 closed defect (bug) (fixed)
WordPress Core setup does not configure XDebug properly
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9.1 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Build/Test Tools | Keywords: | commit fixed-major dev-reviewed |
| Focuses: | Cc: |
Description
The WordPress Core development environment does not include proper Xdebug configuration for debugging from host IDEs like VS Code. While Xdebug is enabled in the PHP container, the client_host setting defaults to localhost, which prevents debugging connections from working when the IDE is running on the host machine.
Steps to Reproduce:
- Clone the wordpress-develop repository
- Set
LOCAL_PHP_XDEBUG=truein.envto enable Xdebug - Run the WordPress instance with instructions given in README.
- Configure VS Code to listen for Xdebug connections.
- Set breakpoints in PHP files
- Visit the WordPress site with Xdebug session enabled
Result:
Breakpoints are not triggered.
Expected:
Breakpoints should be triggered.
Attachments (2)
Change History (35)
#2
follow-up:
↓ 3
@
8 months ago
- Keywords reporter-feedback added
- Severity changed from minor to normal
#3
in reply to:
↑ 2
;
follow-up:
↓ 4
@
8 months ago
Replying to SirLouen:
What system are you using?
I'm on W11 with WSL2 and Ubuntu 24.04 and its working flawlessly.
I am using MacOS Sequoia (with Orbstack).
When you talk about breakpoints, apart from the bps in your ID, I'm assuming you are using either
xdebug_break()in code, or passing aXDEBUG_somethingquery var to the browser, or using a extension that injects it, right?
Xdebug uses
xdebug.start_with_request=triggerso you must trigger it; it's not perma-running as in regular setups.
Yup, I am using an extension (Xdebug Helper by JetBrains) in Chrome for the trigger.
#4
in reply to:
↑ 3
;
follow-up:
↓ 5
@
8 months ago
Replying to jdeep:
I am using MacOS Sequoia (with Orbstack).
Networking in that Orbstack might be the culprit specially if you happen to find that xdebug.client_host=host.docker.internal works for you
Which client are you using to connect to Xdebug?
#5
in reply to:
↑ 4
@
8 months ago
Replying to SirLouen:
Replying to jdeep:
I am using MacOS Sequoia (with Orbstack).
Networking in that Orbstack might be the culprit specially if you happen to find that
xdebug.client_host=host.docker.internalworks for you
Possible. However, after a lot of digging through docs and StackOverflow, I found that this is common issue with XDebug running inside a container. For example, PHPStorm's Xdebug client puts xdebug.client_host=host.docker.internal in config as well.
Which client are you using to connect to Xdebug?
I am using PHPDebug (by XDebug.org) extension in VSCode.
#6
follow-up:
↓ 7
@
8 months ago
I am using PHPDebug (by XDebug.org) extension in VSCode.
What is the VSCode you are using?
#7
in reply to:
↑ 6
;
follow-up:
↓ 8
@
8 months ago
Replying to SirLouen:
I am using PHPDebug (by XDebug.org) extension in VSCode.
What is the VSCode you are using?
Version: 1.103.2 (Universal)
Commit: 6f17636121051a53c88d3e605c491d22af2ba755
Date: 2025-08-20T16:45:34.255Z (3 wks ago)
Electron: 37.2.3
ElectronBuildId: 12035395
Chromium: 138.0.7204.100
Node.js: 22.17.0
V8: 13.8.500258-electron.0
OS: Darwin arm64 24.6.0
#8
in reply to:
↑ 7
;
follow-up:
↓ 9
@
8 months ago
Replying to jdeep:
Version: 1.103.2 (Universal) Commit: 6f17636121051a53c88d3e605c491d22af2ba755 Date: 2025-08-20T16:45:34.255Z (3 wks ago) Electron: 37.2.3 ElectronBuildId: 12035395 Chromium: 138.0.7204.100 Node.js: 22.17.0 V8: 13.8.500258-electron.0 OS: Darwin arm64 24.6.0
My bad. I was willing to ask, what is the launch.json file you are using in VSCode.
#9
in reply to:
↑ 8
@
8 months ago
Replying to SirLouen:
Replying to jdeep:
Version: 1.103.2 (Universal) Commit: 6f17636121051a53c88d3e605c491d22af2ba755 Date: 2025-08-20T16:45:34.255Z (3 wks ago) Electron: 37.2.3 ElectronBuildId: 12035395 Chromium: 138.0.7204.100 Node.js: 22.17.0 V8: 13.8.500258-electron.0 OS: Darwin arm64 24.6.0My bad. I was willing to ask, what is the
launch.jsonfile you are using in VSCode.
Yeah. This is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www": "${workspaceFolder}",
"/var/www/src": "${workspaceFolder}/src",
"/var/www/build": "${workspaceFolder}/build"
},
"hostname": "0.0.0.0",
"xdebugSettings": {
"max_children": 128,
"max_data": 2048,
"max_depth": 3
}
},
]
}
#10
@
8 months ago
I've tested it, and it works for me with the Docker host.docker.internal hostname explicitly added in the PHP config.
Your VSCode file looks good to me.
#12
@
4 months ago
- Keywords commit added; needs-testing removed
- Milestone changed from Awaiting Review to 6.9.1
- Owner set to SirLouen
- Status changed from new to reviewing
I'm starting to have the same issue; I'm not sure why. I remember that I triaged this some months ago, so looking back in my history, I found this.
So basically I've tested it, and I can confirm that this patch solves this problem. ✅
This ticket was mentioned in Slack in #core by sirlouen. View the logs.
4 months ago
#14
follow-up:
↓ 15
@
4 months ago
Xdebug is working for me on a Mac, with and without this patch. Gemini explained to me why it works on a Mac without the patch but it fails on Windows with WSL:
Windows (WSL2): WSL2 runs as a distinct, lightweight Linux Virtual Machine. It has its own IP address and its own "Loopback" interface (
127.0.0.1). When Xdebug tries to connect tolocalhost, it connects to the container's own internal network. Since PhpStorm isn't installed inside the container, the connection fails.
The Fix:
host.docker.internalis a special DNS name Docker adds to the container specifically to resolve to the Host's internal IP address.
macOS: While also a VM, Docker Desktop for Mac binds ports and handles networking differently to make it feel more "native." However, relying on localhost here is technically "incorrect" for Docker and often breaks if you change network modes.
Moreover, it suggests an additional "universal" fix:
Instead of forcing your colleague to change their config to
host.docker.internaland you keepinglocalhost, you should both use the Discovery mode. This works on Mac, Windows, and Linux without changing a single line of config.
Change your php.ini (or Xdebug config) to:
# 1. Turn on Discovery xdebug.discover_client_host = true # 2. Set client_host as a fallback only (can be left as localhost or host.docker.internal) xdebug.client_host = host.docker.internalWhy this is better: When
discover_client_hostistrue, Xdebug ignores theclient_hostsetting. Instead, it looks at the incoming HTTP request headers (like$_SERVER['REMOTE_ADDR']) to find the IP address of the computer that sent the request (your computer). It then connects back to that IP automatically.
Summary for your Windows Colleague
Because WSL2 is a real Linux VM, localhost points to the Linux VM, not Windows. You have to use host.docker.internal so the container knows how to route out of the VM and talk to PhpStorm on Windows.
In reading the Xdebug docs about discover_client_host, it seems to make sense. Do note there is a warning, however:
Please note that there is no filter available, and anybody who can connect to the webserver will then be able to start a debugging session, even if their address does not match xdebug.client_host.
But since the wordpress-develop environment is local, there doesn't seem to be any concern here.
So should the patch be amended to include xdebug.discover_client_host=true?
#15
in reply to:
↑ 14
@
4 months ago
Replying to westonruter:
Xdebug is working for me on a Mac, with and without this patch. Gemini explained to me why it works on a Mac without the patch but it fails on Windows with WSL:
Yes, xdebug is a bit hateful occasionally. Now I'm testing, and it's working for me without any changes to the php-config.ini file.
I think that adding these two little tweaks, both the client_host and the discover_client_host have proven to fix issues and won't do any harm and will provide more robustness to any run.
#19
follow-ups:
↓ 20
↓ 23
@
4 months ago
What is the reason to backport the patch to 6.9? It looks like it's something related to local development.
#20
in reply to:
↑ 19
@
4 months ago
Replying to wildworks:
What is the reason to backport the patch to
6.9? It looks like it's something related to local development.
I found out that these things are easily backported because if you need to work on such version you have the fix handy available. Same when the env:install was improved last year: You had a faster env:install for branch related topics backported.
But it could not be backported also, its kind of optional. Personally I rarely use minor versions on development, so its superniche but I saw that Weston like to backport this kind of tool patches :)
This ticket was mentioned in Slack in #core by jorbin. View the logs.
4 months ago
#22
@
4 months ago
If we backport it, I think this may be best backported all the way to 4.7 so that the env functions the same on all versions recieving security updates
#23
in reply to:
↑ 19
@
4 months ago
Replying to wildworks:
What is the reason to backport the patch to
6.9? It looks like it's something related to local development.
In general, the goal is always to keep the underlying build tools and environments as consistent as reasonably possible across all branches eligible to receive security updates. This ensures contributors can switch branches to test how a bug was introduced, how something behaved differently, etc.
I don't have strong feelings around how far to backport this one. I lean towards backporting to 6.9 only for now as that branch is actively supported and using xDebug to investigate a problem is more likely. Unless something is broken, tooling-related changes are typically backported together to avoid creating noise unnecessarily. I'm not sure that there are any other changes to backport at this time. We could always include this the next time there is a grouped backport.
Someone would need to go back to 4.7 and verify that the changes work as expected on both platforms before we can consider going back past 6.9, though.
This ticket was mentioned in Slack in #core by jorbin. View the logs.
4 months ago
#25
@
4 months ago
Happy to defer to @desrosj since he's done more work on the local env. Let's just go to 6.9.
Since this is a bug that affects Windows, I am going to defer to a committer using Windows to do the review for backport.
#26
@
4 months ago
In general, the goal is always to keep the underlying build tools and environments as consistent as reasonably possible across all branches eligible to receive security updates. This ensures contributors can switch branches to test how a bug was introduced, how something behaved differently, etc.
Thanks for the detailed explanation.
Since this is a bug that affects Windows, I am going to defer to a committer using Windows to do the review for backport.
In my environment (WSL2 on Windows 11), the problem never occurred in the first place, but the change looks good.
This is off topic, but should we gitignore .vscode/launch.json?
#27
@
4 months ago
This is off topic, but should we gitignore .vscode/launch.json?
No. Ignoring individual developer tools can quickly balloon. For people using git, they can ignore can use .git/info/exclude to ignore files related to their tools and for people using svn there is the global-ignores svn configuration file.
#28
@
4 months ago
- Keywords dev-reviewed added; dev-feedback removed
Re-opening for backport consideration.
Approve backport to the 6.9 branch.
This ticket was mentioned in Slack in #core by wildworks. View the logs.
4 months ago
#30
@
4 months ago
This ticket was brought up in today's 6.9.1 bug scrub, and if there are no objections, I will make a backport commit to the 6.9 branch.
What system are you using?
I'm on W11 with WSL2 and Ubuntu 24.04 and its working flawlessly.
When you talk about breakpoints, apart from the bps in your ID, I'm assuming you are using either
xdebug_break()in code, or passing aXDEBUG_somethingquery var to the browser, or using a extension that injects it, right?Xdebug uses
xdebug.start_with_request=triggerso you must trigger it; it's not perma-running as in regular setups.