0

I have Laravel Sail installed in WSL, and I'm trying to debug the application using Xdebug. This only works if I enter the WSL IP address directly into the browser (http://172.17.170.44:8000). If I enter http://localhost:8000 (which I need), the page only loads, but it doesn't connect to PhpStorm - see screen

enter image description here

My configuration:

20-xdebug.ini

[XDebug]
zend_extension = xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = true
xdebug.idekey = PHPSTORM
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003

.env

# Xdebug
SAIL_XDEBUG_MODE=develop,debug,coverage
SAIL_XDEBUG_CONFIG="client_host=laravel.test"

part of compose.yaml

services:
  laravel.test:
    build:
      context: ./vendor/laravel/sail/runtimes/8.4
      dockerfile: Dockerfile
      args:
        WWWGROUP: '${WWWGROUP}'
        MYSQL_CLIENT: mariadb-client
    image: sail-8.4/app
    extra_hosts:
      - 'host.docker.internal:host-gateway'
    ports:
      - '${APP_PORT:-80}:80'
    environment:
      WWWUSER: '${WWWUSER}'
      LARAVEL_SAIL: 1
      XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
      XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
      IGNITION_LOCAL_SITES_PATH: '${PWD}'
    volumes:
      - '.:/var/www/html'
      - './20-xdebug.ini:/etc/php/8.4/cli/conf.d/20-xdebug.ini'
    networks:
      - sail
    depends_on:
      - mariadb
      - redis
      - mongodb
      - elasticsearch
2
  • Can you show the CLI Interpreter settings of phpstorm? Commented Nov 11 at 3:26
  • Add the log messages from the screenshot as markdown table / text to your question please. I think only the log lines are necessary. Commented Nov 11 at 9:11

1 Answer 1

0

Things are always a bit ify in wsl, it takes some trial and error to figure things out.
That being said, your problem could be ip mapping:

First off I would set xdebug.discover_client_host to false. this won't work correctly under wsl.

Secondly instead of host.docker.internal use the ip of your host system as viewed from insde wsl (i hope that makes sense - run ip route show | grep default in wsl)
or by running ipconfig in a cmd shell

Ethernet adapter vEthernet (WSL):

  Connection-specific DNS Suffix  . :
  Link-local IPv6 Address . . . . . : fe80::2c4:def8:56a0:23a0%20
  IPv4 Address. . . . . . . . . . . : 172.18.144.1
  Subnet Mask . . . . . . . . . . . : 255.255.240.0

Regardless of how you pass this ip to your container (env file or some bootstrap process), make sure this ip ends up in xdebug.client_host when you check with phpinfo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.