Added xdebug 3.0 to the project using xdebugs built-in env vars. #209
+18
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm aware that this has been attempted in previous PRs that have been denied but I thought I'd take another chance as I believe my implementation has a rather small footprint and may be more palatable to the maintainers of this repository.
I do understand their desire to keep this project lean but I have a hard time understanding how a step debugger isn't included in any basic local development environment.
Implementation
This installs Xdebug 3.0 using the php7.4 and php8.0 packages and relies on the two built in env vars already provided by xdebug:
XDEBUG_MODE
andXDEBUG_CONFIG
to control and configure the extension. These are mapped directly toSAIL_XDEBUG_MODE
andSAIL_XDEBUG_CONFIG
that can be controlled in the projects .env file.Configuraiton
XDEBUG_MODE is set to
off
by default. To enable xdebug you simply need to set the appropriate mode when starting your containers:XDEBUG_CONFIG is set to
client_host=host.docker.internal
by default so it will be properly configured out of the box to work on Mac and Windows.Since host.docker.internal isn't available in containers running on Linux hosts, Linux users need to update this env var in their projects:
SAIL_XDEBUG_CONFIG="client_host=<host-ip-address>"
They can get the host ip address by running the following command:
CLI Usage
I added a
sail debug
command that can be used to start a debugging session when running an artisan command:Browser Usage
If you want to debug a web session, follow the instructions provided by xdebug for initiating an xdebug session from the web browser.
Browser Extensions
Current Issue
There is currently an issue with the
serve
command that prevents xdebug configured via env variables from working with the built-in webserver but I've included a PR to laravel/framework to alleviate this: laravel/framework#38211Once that is merged in we can fix this issue by overriding the env vars that are passed thru to the built-in webserver: