How to enable Xdebug in Laravel Sail
1. Set the appropriate mode(s)
.env
SAIL_XDEBUG_MODE=develop,debug
2. Publish Sail's docker files
  1. sail artisan sail:publish
INFO  Publishing [sail-docker] assets.

Copying directory [vendor/laravel/sail/runtimes] to [docker] ..................................... DONE

INFO  Publishing [sail-database] assets.

Copying directory [vendor/laravel/sail/database] to [docker] ..................................... DONE
3. Create ext-xdebug.ini file with the following content
docker/8.3/ext-xdebug.ini
xdebug.start_with_request=yes
xdebug.discover_client_host=true
xdebug.max_nesting_level=256
xdebug.remote_handler=dbgp
xdebug.client_port=9003
xdebug.idekey=VSCODE
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.var_display_max_depth=5
4. Include the Xdebug configurations in the Dockerfile
docker/8.3/Dockerfile
COPY ext-xdebug.ini /etc/php/8.3/cli/conf.d/ext-xdebug.ini
5. Rebuild all of the Sail containers
  1. sail build --no-cache
6. Install PHP Debug Adapter for Visual Studio Code 7. Add the debugging configuration to Visual Studio Code
.vscode/launch.json
{
    "name": "Listen for Xdebug",
    "type": "php",
    "request": "launch",
    "port": 9003,
    "log": false,
    "externalConsole": false,
    "pathMappings": {
        "/var/www/html": "${workspaceFolder}",
    },
    "ignore": [
        "**/vendor/**/*.php",
    ],
}
8. Check if Xdebug is working correctly