Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XDebug on port 9000 with a virtual machine - EADDRINUSE :::9000

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?

like image 457
Enrique Moreno Tent Avatar asked Jun 01 '18 13:06

Enrique Moreno Tent


4 Answers

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.

like image 94
Webvoid Avatar answered Oct 21 '22 12:10

Webvoid


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:

  • updating your IDE xdebug configs from port 9000 to 9001;
  • 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

like image 39
yarche Avatar answered Oct 21 '22 14:10

yarche


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.

like image 44
Enrique Moreno Tent Avatar answered Oct 21 '22 13:10

Enrique Moreno Tent


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.

like image 43
raison Avatar answered Oct 21 '22 12:10

raison