If you are not a newcomer to PHP, you may hear about Xdebug — A PHP extension that gives you the power of debugging and profiling capabilities.

Maybe… you are the fans of dd()var_dump(), or print_r(), but Xdebug gives you more powerful tools with IDE to capture the nasty bug! (and perhaps save you from the sleepless night)

I assume you have started your project with Laravel Sail. If not, you can read  Kickstart your Laravel Web App using Laravel Sail.

Sadly, you cannot choose to add the Xdebug package directly as you saw from the  official documentation. There is a debate about Xdebug support in the laravel/sail repo; you may take a look if you are interested.

However, it can’t stop you from customizing YOUR Docker container! Let us step-by-step to add Xdebug to our project.

🐳 Edit Docker Configuration

1. Make sure you sail up -d before we start.

2. Execute sail artisan sail:publish to publish the configuration files.

You will see the docker folder and docker-compose.yml file.

3. You can sail down now when we are editing the docker config files.

4. Add Line 10 & Line 11 for the Xdebug on/off switch(XDEBUG) and port number(XDEBUG_PORT) in docker-compose.yml. Your .env file should also set APP_DEBUG as true.

#xdebug #vscode #laravel #laravel-sail

Xdebug Laravel Sail project in VS Code
4.05 GEEK