Let me start by saying I know this question has been asked, but I've been through all the answers I could find and none so far have worked for me. I'm also a frontend dev and my networking experience is pretty limited, so forgive my ignorance.
I'm running Docker Desktop on Windows 11 using WSL2 integration. I'm running a local WordPress install through Docker-Compose and can't for the life of me get Xdebug to connect.
Here's my docker-compose.yml:
version: "3.1"
services:
wordpress:
build: ./
ports:
- "80:80"
volumes:
- ./wp-content:/var/www/html/wp-content:delegated
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
depends_on:
- db
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
volumes:
- db-data:/var/lib/mysql:delegated
volumes:
db-data:
My Dockerfile:
FROM wordpress:latest
# We're going to use this path multile times. So save it in a variable.
ARG XDEBUG_INI="/usr/local/etc/php/conf.d/xdebug.ini"
# Install AND configure Xdebug
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& echo "[xdebug]" > $XDEBUG_INI \
&& echo "xdebug.mode = debug" >> $XDEBUG_INI \
&& echo "xdebug.start_with_request = yes" >> $XDEBUG_INI \
&& echo "xdebug.discover_client_host = 0" >> $XDEBUG_INI \
&& echo "xdebug.client_port = 9003" >> $XDEBUG_INI \
&& echo "xdebug.client_host = host.docker.internal" >> $XDEBUG_INI \
&& echo "xdebug.log = /tmp/xdebug.log" >> $XDEBUG_INI
And my launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"stopOnEntry": true,
"pathMappings": {
"/var/www/html": "${workspaceRoot}"
},
},
]
}
When I call xdebug_info()
, I get the following error that others have mentioned before:
[Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port).
Interestingly, if I ifconfig
from inside a WSL terminal and replace xdebug.client_host = host.docker.internal
with my specified IP, the error message changes to:
[Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: wsl2_ip_here:9003 (through xdebug.client_host/xdebug.client_port).
Any help with this would be much appreciated. I feel like I'm so close and am just missing some piece of connectivity. Thanks so much in advance.