I am trying to debug Laravel code on Visual Studio Code using Xdebug. I am using Docker container that works as server.
But I am getting this error when try to debug
You can use PHP Debug VS Code extension to connect with XDebug. PHP-FPM are run at port 9000 by default, so it's best to change the xdebug.remote_port
settings to another port (e.g. 9001
):
// launch.json
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"pathMappings": { "/": "${workspaceRoot}/" },
"port": 9001
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9001
}
]
If you are using Docker, Use these settings in your php.ini
file :
//php.ini
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = host.docker.internal
xdebug.remote_port = 9001
As of Docker version 18.03, host.docker.internal
points to host IP address on Mac / Windows. For Linux, you can use this workaround.
Once these settings are set, you are good to go.