I am running my Symfony application on a VirtualBox VM. PHP is running with XDebug, and it is properly configured. I know this because other people have managed to make it work with a snapshot of the same VM.
When I try to configure in VS Code XDebug, I use the following launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
But when I click on "Start Debugging: Listen for XDebug", I get the following error:
ERROR: listen EADDRINUSE :::9000
I tried killing the process that is using that port... and for my surprise that was the virtual machine I was trying to connect to.
What did I miss in this configuration?
You are trying to do a launch
operation in your launch.json
, which will result as vscode trying to start a new instance of php with an xdebug on port 9000.
Try replacing your launch
config by an attach
config.
Hope it helps.
port 9000 is frequently used by default configurations of other apps (for example native apache on MacOsX), also VMs, Docker containers, etc...
A reliable solution would be - to use a different port. For example, 9001 :)
That means:
adding to your php.ini (xdebug.ini) the line
xdebug.remote_port=9001
Also, you can check your 9000 port usage by some tool like telnet
I found the answer myself just about.
The problem was laying on the configuration of Virtualbox.
On the Network settings, there was a port forwarding for the port 9000, which blocked my debugger from running locally. Once removed, it worked without problem.
On MacOS we can use the terminal to determine what is open on port 9000 with the following:
sudo lsof -nP -i4TCP:9000 | grep LISTEN
We can use sudo above so we see processes that are not owned by the logged in account.
For example when I did the above I got:
php-fpm 110 root 6u IPv4 0x5cb825c4aa80be09 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 261 _www 0u IPv4 0x5cb825c4aa80be09 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 262 _www 0u IPv4 0x5cb825c4aa80be09 0t0 TCP 127.0.0.1:9000 (LISTEN)
We can then end the processes with this command:
sudo kill 110
Then we will have the port free so we can start up Xdebug without a conflict.
That solved it for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With