Ask Your Question
4

How can Xdebug be used in conjunction with VSCode for Laravel on Sail and WSL2?

asked 2021-08-31 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-01-30 22:00:00 +0000

lalupa gravatar image

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-08-31 11:00:00 +0000

Seen: 22 times

Last updated: Jan 30 '23