I am trying to setup xdebug using laravel sail with latest version, on my Ubuntu 20.04.3 LTS desktop,
ie
php 8.1
laravel 9
with below mentioned details to .env file
SAIL_XDEBUG_MODE=develop,debug
SAIL_XDEBUG_CONFIG="client_host=172.23.0.1"
but when i run sail debug migrate
, returns
Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: 172.23.0.1:9003 (through xdebug.client_host/xdebug.client_port)
When I tried finding IP, it change every time
docker inspect -f {{range.NetworkSettings.Networks}}{{.Gateway}}{{end}} <container-name>
return different IP like 172.25.0.1
2
Answers
Solution
Just put this in your
.env
the followingJust as in Windows and MacOS
Now you can run
sail debug migrate
or justsail debug
in order to test it.Explanation
You’re probably using
sail down
to ‘stop’ the containers, but as the docker documentation stated:Thus, every time you’re running
sail up
it will regenerate the network with a new IP address.You could use
sail stop
, but when you’re working with multiple projects it could become a hassle to edit the ports (in the.env
file) of every service per project.As per v1.10.1, sail incorporate the
extra_host
option, essentially detecting the IP of the host machine:Edit: Do not forget to update Docker since this only works with Docker v20.10+.
I’ve been searching on this till I read about it being a firewall port issue here.
Then I remember the
services.[laravel.test].ports
on docker-compose.yml and tried to add9003:9003
ports.Try adding the XDebug ports: