Tag Archives: XDEBUG

Laravel-VSCODE X-debug configuration

Table of contents

  1. Install x-debug
  2. Configure x-debug
  3. Run the x-debug listener in VS-Code
  4. Configure the task to launch laravel
  5. Debug the project

In this article we assume that php is already installed.

Install x-debug

sudo apt-get install php-xdebug

Configure x-debug

Run phpinfo() to find which php.ini you need to edit:

php -i | grep "Loaded Configuration File"

For example the path might be:

/etc/php/8.3/cli/php.ini

You need to edit the php.ini file to configure (x-debug 3). You may change the values according to your needs. The default port of x-debug is 9000 but it is highly recommended to change it because more often that not that port is used by another application.

[xdebug]
xdebug.mode=debug
xdebug.client_port=11887
xdebug.client_host=0.0.0.0
xdebug.remote_handler=dbgp
xdebug.start_with_request=yes
xdebug.discover_client_host=0
xdebug.idekey=VSCODE
xdebug.show_error_trace = 1
xdebug.max_nesting_level=250
xdebug.var_display_max_depth=10
xdebug.log=/tmp/xdebug.log

Run the x-debug listener in VS-Code

In VS Code, install the plugin for x-debug

Then add in the launch.json:

{
"version": "0.2.0",
"configurations": [
{
"name": "Listen with Xdebug",
"type": "php",
"request": "launch",
"port": 11887
}
]
}

You can run press F5 to start the listener. Once you do, you may launch the Laravel project however you want and it should stop at the break points.

It is recommended to run the listener BEFORE the Laravel application.

Configure the task to launch laravel

Create the task to launch Laravel.

For example:

{
"version": "2.0.0",
"tasks": [
{
"label": "php artisan serve",
"type": "shell",
"command": "php artisan serve",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [],
"isBackground": true
},
{
"label": "php artisan test",
"type": "shell",
"command": "php artisan test",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "shared"
}
}
]
}

Debug the project

In order to debug the project, You need to do the following steps:

  • Press F5 to launch the x-debug listener
  • Press CTRL+SHIFT+P to run the task that runs Laravel (php artisan serve)