You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/blog/xdebug-step-debugging-understanding-and-troubleshooting.md
+9-16Lines changed: 9 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ DDEV:
58
58
2. Configures Xdebug to connect to `host.docker.internal:9003`
59
59
3. Sets up the necessary environment variables and configuration
60
60
61
-
The key technical detail is `host.docker.internal` - this is a special DNS name that Docker provides to containers, resolving to the host machine's IP address. This allows PHP running inside the container to connect to your IDE running on your host machine.
61
+
The key technical detail is `host.docker.internal` - this is a special DNS name that DDEV+Docker provide to containers, resolving to the host machine's IP address. This allows PHP running inside the container to connect to your IDE running on your host machine.
62
62
63
63
### Basic Commands
64
64
@@ -70,19 +70,18 @@ The key technical detail is `host.docker.internal` - this is a special DNS name
70
70
71
71
## Why DDEV Xdebug "Just Works"
72
72
73
-
One of DDEV's proudest achievements is that Xdebug typically works without any configuration. This seems simple, but it's solving a complex problem: PHP running inside a Docker container needs to connect back to your IDE on your host machine, and the container has no inherent knowledge of how to reach the host.
73
+
One of our proudest achievements with DDEV is that Xdebug typically works without any configuration. This seems simple, but it's solving a complex problem: PHP running inside a Docker container needs to connect back to your IDE on your host machine, and the container has no inherent knowledge of how to reach the host.
74
74
75
75
The solution is `host.docker.internal` - a special hostname that resolves to the host machine's IP address from the container's perspective. The challenge is that this works differently across platforms:
76
76
77
-
-**macOS and Windows (Docker Desktop)**: Automatically provides`host.docker.internal`
78
-
-**Linux**: No built-in `host.docker.internal` support
77
+
-**macOS and Windows**: Some Docker providers like Docker Desktop and Colima automatically provide`host.docker.internal`
78
+
-**Linux**: No direct built-in `host.docker.internal` support
79
79
-**WSL2**: Complex networking scenarios depending on NAT vs. mirrored mode
80
80
81
81
DDEV automatically detects your environment and configures `host.docker.internal` correctly:
82
82
83
-
- On Linux, DDEV adds the host gateway IP to `/etc/hosts` in the container
83
+
- On Linux, DDEV use the host gateway feature of docker-compose
84
84
- On WSL2, DDEV determines whether to use the Windows host IP or the WSL2 IP based on your configuration
85
-
- On all platforms, DDEV validates the IP and reconfigures if needed
86
85
87
86
This means when you run `ddev xdebug on`, the extension is already configured to connect to `host.docker.internal:9003`, and that hostname reliably resolves to wherever your IDE is listening.
88
87
@@ -101,12 +100,6 @@ You can verify what `host.docker.internal` resolves to:
101
100
ddev exec getent hosts host.docker.internal
102
101
```
103
102
104
-
Or use the new info command:
105
-
106
-
```bash
107
-
ddev xdebug info
108
-
```
109
-
110
103
When Xdebug tries to connect, it uses this hostname to reach your IDE. The connection path is:
111
104
112
105
```
@@ -144,7 +137,7 @@ ddev config global --xdebug-ide-location=wsl2
144
137
ddev config global --xdebug-ide-location=container
145
138
```
146
139
147
-
**Different Port**: If you need to use a different port than 9003, create `.ddev/php/xdebug_client_port.ini`:
140
+
**Different Port**: If you need to use a different port than 9003 (very unusual), create `.ddev/php/xdebug_client_port.ini`:
148
141
149
142
```ini
150
143
xdebug.client_port=9000
@@ -158,7 +151,7 @@ xdebug.client_port=9000
158
151
159
152
The most common debugging issue is setting a breakpoint in code that never runs. You might set a breakpoint in a function that's not called, a conditional branch that's not taken, or a file that's not included.
160
153
161
-
**Solution**: Start with a breakpoint in the main entry point, usually `index.php` or `web/index.php`. This ensures your breakpoint will definitely be hit. Once you confirm Xdebug is working, you can move your breakpoint to the specific code you want to debug.
154
+
**Solution**: Start studying your situation with a breakpoint in the main entry point, usually `index.php` or `web/index.php`. This ensures your breakpoint will definitely be hit. Once you confirm Xdebug is working, you can move your breakpoint to the specific code you want to debug.
162
155
163
156
### Incorrect Path Mappings
164
157
@@ -228,7 +221,7 @@ If debugging works with the firewall off, you need to add a firewall rule for po
228
221
229
222
## The New `ddev utility xdebug-diagnose` Tool
230
223
231
-
DDEV v1.25 introduces an experimental diagnostic tool that automatically checks your Xdebug configuration and connectivity:
224
+
DDEV v1.25 introduces a diagnostic tool that automatically checks your Xdebug configuration and connectivity:
232
225
233
226
```bash
234
227
ddev utility xdebug-diagnose
@@ -375,7 +368,7 @@ ddev config global --xdebug-ide-location=""
375
368
Only set it for special cases:
376
369
377
370
-`wsl2` - VS Code with WSL extension or IDE running in WSL2
0 commit comments