简体   繁体   English

带有虚拟机的端口9000上的XDebug - EADDRINUSE ::: 90000

[英]XDebug on port 9000 with a virtual machine - EADDRINUSE :::90000

I am running my Symfony application on a VirtualBox VM. 我在VirtualBox VM上运行我的Symfony应用程序。 PHP is running with XDebug, and it is properly configured. PHP正在使用XDebug运行,并且已正确配置。 I know this because other people have managed to make it work with a snapshot of the same VM. 我知道这一点,因为其他人已设法使其与同一个VM的快照一起工作。

When I try to configure in VS Code XDebug, I use the following launch.json 当我尝试在VS Code XDebug中配置时,我使用以下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: 但是当我点击“开始调试:侦听XDebug”时,我收到以下错误:

ERROR: listen EADDRINUSE :::9000 错误:听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? 我在这个配置中错过了什么?

port 9000 is frequently used by default configurations of other apps (for example native apache on MacOsX), also VMs, Docker containers, etc... 端口9000经常被其他应用程序的默认配置使用(例如MacOsX上的本机apache),还有VM,Docker容器等......

A reliable solution would be - to use a different port. 一个可靠的解决方案是 - 使用不同的端口。 For example, 9001 :) 例如,9001 :)

That means: 这意味着:

  • updating your IDE xdebug configs from port 9000 to 9001; 将IDE xdebug配置从端口9000更新到9001;
  • adding to your php.ini (xdebug.ini) the line 添加到你的php.ini(xdebug.ini)行

     xdebug.remote_port=9001 

Also, you can check your 9000 port usage by some tool like telnet 此外,您可以通过某些工具(如telnet)检查您的9000端口使用情况

On MacOS we can use the terminal to determine what is open on port 9000 with the following: 在MacOS上,我们可以使用终端确定端口9000上打开的内容,具体如下:

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. 我们可以使用上面的sudo,因此我们可以看到不属于登录帐户的进程。

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. 然后我们将释放端口,这样我们就可以在没有冲突的情况下启动Xdebug。

That solved it for me. 这解决了我。

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 . 您正在尝试在launch.json执行launch操作,这将导致vscode尝试使用端口9000上的xdebug 启动 php的新实例。

Try replacing your launch config by an attach config. 尝试通过attach配置替换launch配置。

Hope it helps. 希望能帮助到你。

I found the answer myself just about. 我自己找到了答案。

The problem was laying on the configuration of Virtualbox. 问题在于Virtualbox的配置。

On the Network settings, there was a port forwarding for the port 9000, which blocked my debugger from running locally. 在网络设置中,端口9000有一个端口转发,阻止我的调试器在本地运行。 Once removed, it worked without problem. 一旦删除,它没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM