laravel / sail

Docker files for running a basic Laravel application.
https://laravel.com/docs/sail
MIT License
1.69k stars 477 forks source link

Xdebug not hitting breakpoints #421

Closed titantwentyone closed 2 years ago

titantwentyone commented 2 years ago

Also...

Description:

XDebug not hitting breakpoints

Steps To Reproduce:

Below are the minimum steps I needed to recreate the issue.

  1. laravel new xdebug-issue
  2. cd xdebug-issue/
  3. php artisan sail:install (Only selected option 2 - MariaDB)
  4. Added SAIL_XDEBUG_MODE=develop,debug to .env (note that according to the docs, I do not need to add SAIL_XDEBUG_CONFIG as my installed versions of docker and docker-compose exceed those required to manually specifiy the host.docker.internal var)

Internally, the XDEBUG_CONFIG environment variable is defined as client_host=host.docker.internal so that Xdebug will be properly configured for Mac and Windows (WSL2). If your local machine is running Linux, you should ensure that you are running Docker Engine 17.06.0+ and Compose 1.16.0+. Otherwise, you will need to manually define this environment variable as shown below.

  1. sail up
  2. Add breakpoint to routes/web.php:
Route::get('/', function () {
    return view('welcome'); //breakpoint here
});
  1. Visit http://localhost/ - breakpoint is not hit

Config for VSCode is:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Sail Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html": "${workspaceFolder}"
            },
            "ignore": ["**/vendor/**/*.php"],
            "xdebugSettings": {
                "max_data": 65536,
                "show_hidden": 1,
                "max_children": 100,
                "max_depth": 3
            }
        },
    ]
}

I note that the logs from Sail state

laravel.test_1  | [Tue May 31 17:05:42 2022] Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(

I'm really unsure whether this is an issue with Sail (specifically on Linux machines) or something is missing from the docs (again - something as Linux users we need to do).

driesvints commented 2 years ago

Hey there,

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!

titantwentyone commented 2 years ago

@driesvints Managed to track down my issue which was the firewall not accepting connections on 9003. Generally, the firewall on Linux distros are quite restrictive by default and I've seen the same issue reported here in lots of places - many with no solution and I'm wondering if a small note would be worth adding to the docs? I think people will be so fixated on a config issue with docker/sail that they may miss this. Could save a lot of heartache. Literally just one sentence - "Make sure your docker host accepts connections through the port used by xdebug, typically 9003.".

driesvints commented 2 years ago

@titantwentyone feel free to attempt a PR to the docs 👍