Search code examples
vagrantphpstormxdebug

How to avoid "Incoming connections" popup in PhpStorm for several vagrant servers


I have two vagrant servers and according PhpStorm projects for them. I configured xdebug for both as well. Debugging works. But when I added the second server I have a popup "Incoming connections" with options of my projects. It asks which project xdebug should relate the incoming request to. I found the issue. It happens because both vagrant machines have the same ip. And PhpProjects also have the same ip for projects. So it is quite naturally that PhpStorm can not define a write project for debugging. But should I do. First, I tried to change vagrant machine ip:

sudo ifconfig enp0s3 192.168.0.253 netmask 255.255.255.0

This command hangs on. Also tried to add a config in /etc/network/interfaces:

iface enp0s3 inet static
      address 192.168.0.253
      netmask 255.255.255.0

No success too. I searched for vagrant way to change ip, but nothing. I also tried to find a way to tell xdebug which ip it should send to PhpStorm but how?

It's unlikely that only I have this problem but did not find any relevant information about this issue.


Solution

  • The sulution turned out to be easy. Virtual box has a specific option for a machine ip. One can configure it as follows (Vagrantfile):

    config.vm.provider "virtualbox" do |vb|
        vb.customize ['modifyvm', :id, '--natnet1', '192.168/16']
    

    This will setup an ip different from the default one 10.0.2.15. Basically, instead of 192.168/16 could be any valid ip you wish. But following given example a random ip will be set for the machine. This ip could be found by connecting to a machine (ssh) and checking ip configuration as any machine of your OS. In ubuntu ifconfig works.

    Then you need to create a server in PhpStorm with obtained ip in settings Languages and frameworks > PHP > Servers. Most likely you will also need to setup path mapping for the server.