I have read posts like
visual studio code PHP debugging not working and XDebug not working in VScode for php debugging but can’t manage to make this work properly in my Laravel projects.
I’m using XDebug V3 and it works on single php files but not on laravel projects. I use VSCode.
My configuration:
Launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"stopOnEntry": true,
"log": true,
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000,
"pathMappings": {
"C:/xampp/htdocs/myLaravelProject": "${workspaceFolder}"
}
}
]
}
php.ini
[XDebug]
zend_extension = xdebug
xdebug.mode = debug
xdebug.start_with_request = trigger
xdebug.remote_port = 9000
xdebug.client_port = 9000
Works:
single file index.php
<?php
$i = 1 + 4;
echo $i; // Breakpoint here works
Doesn’t work: Laravel Project/routes/web.php
<?php
Route::get('/test-breakpoint', function()
{
$i = 1 + 4;
echo $i; // Breakpoint here doesn't work
});
2
Answers
First, Update your php.ini.
Second, add your Laravel project to a workspace and update launch.json file
When using
start_with_request=trigger
, in order to actually activate debugging, XDebug needs to locate the triggerXDEBUG_TRIGGER
. This trigger can be in:Using Laravel I think the easiest way is to use
$_GET
which is achieved by simply addingXDEBUG_TRIGGER=1
to the request you want to debug. For example you’d callhttp://localhost/test-breakpoint?XDEBUG_TRIGGER=1
if you want to run that route with debugging. You can probably also set it in a cookie that only is set on a specific route, but if you choose to do this be aware that Laravel encrypts cookies it sets so you have to use native PHP functions to set this cookie.Even if you don’t activate XDebug with a trigger you can still start it using
xdebug_break()
though this needs to be added to your code which is not always an option.