This guide explains how to enable Xdebug in Laravel Sail for efficient PHP debugging, including configuring the .env
file, publishing Docker files, modifying the container setup, and setting up Visual Studio Code for debugging.
SAIL_XDEBUG_MODE
variable to the appropriate modes SAIL_XDEBUG_MODE=develop,debug,coverage
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
build
context points to the correct service configuration services:
laravel.test:
build:
context: ./docker/8.3
dockerfile: Dockerfile
...
ext-xdebug.ini
file with the following configuration 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
Dockerfile
to include the Xdebug configuration COPY ext-xdebug.ini /etc/php/8.3/cli/conf.d/ext-xdebug.ini
sail build --no-cache
PHP Debug
extension in Visual Studio Code 8. Configure Xdebug in Visual Studio Code {
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": false,
"externalConsole": false,
"pathMappings": {
"/var/www/html": "${workspaceFolder}",
},
"ignore": [
"**/vendor/**/*.php",
],
}