Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To use Xdebug with VSCode for Laravel on Sail and WSL2, follow these steps:

  1. Install Xdebug on your WSL2 instance by running the command below:
sudo apt-get install php-xdebug
  1. Configure Xdebug by adding the following lines to your php.ini file:
[xdebug]
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
  1. Update your VSCode launch.json file with the following configuration:
"configurations": [
    {
        "name": "Listen for Xdebug",
        "type": "php",
        "request": "launch",
        "log": true,
        "pathMappings": {
            "/var/www/html": "${workspaceFolder}"
        },
        "port": 9003,
        "hostname": "127.0.0.1",
        "serverSourceRoot": "/var/www/html/",
        "localSourceRoot": "${workspaceFolder}/",
        "stopOnEntry": false
    }
]
  1. Start your Laravel application and configure Sail to use the Xdebug settings by adding the following lines to your docker-compose.yml file:
services:
  laravel.test:
    environment:
      XDEBUG_MODE: "debug"
      XDEBUG_CONFIG: "client_host=127.0.0.1 client_port=9003"
  1. Finally, start debugging the Laravel application by selecting the Listen for Xdebug configuration in VSCode and placing breakpoints in your code.

Note: Ensure that your WSL2 firewall allows connections through port 9003 by running the command below:

sudo ufw allow 9003