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

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.

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.

Related

VirtualBox networking using vagrant

I need to configure a vm into using vagrant and virtualbox as provider. The issue is related to how to allow network comunication between the virtual machine and the host machine.
Concretly, I need:
Each developer is using a log viewer in his host machine in order to be able see the log messages generated into vm applications. So I need to send log messages to an network address(host) from guest.
Each developer machine has its own ip address, so I'm not able to reference to a single ip since each developer has its host ip address.
Any ideas?
This is how I've set up my VMs lately, hopefully it points you in the right direction.
My requirements were:
enable internet access on a single guest basis
enable access guest to guest
enable access host to guest
avoid IP changes when changing physical network (lan home, lan work, random wlans)
avoid IP clash with various clients VPNs
avoid showing machines on the physical network
To do this use 2 network interfaces on all guests.
Default NAT, enables internet access;
HostOnly network, enables communication host-to-guest and guest-to-guest.
Steps:
Create hostonly network with DHCP (Virtualbox comes with a default one, I customized it)
hostonly network setup
hostonly network DHCP
add network adapters to the guest
NAT(default)
hostonly-network
Start the VM, check with ip a and ip r:
ip addr
ip route (has docker installed too, ignore that)
Create Vagrantfile to provision VM configured like above (I'm using bento/ubuntu-20.04).
NAT is on by default
join the hostonly-network with "modifyvm" (avoid :private_network as it creates a new network that will clash with the one already available), add to Vagrantfile:
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--nic2", "hostonly"]
vb.customize ["modifyvm", :id, "--hostonlyadapter2", "vboxnet1"] #use proper network name here
vb.customize ["modifyvm", :id, "--cableconnected2", "on"]
end
vagrant up
vagrant ssh
ip a will show eth1 as down
try sudo ifup eth1, in my case this failed
edit /etc/network/interfaces and add this:
allow-hotplug eth1
iface eth1 inet dhcp
sudo ifup eth1 should work now and get an ip from the DHCP of the host-only network
Probably these last steps could be added to vagrant shell provisioning but I'm still new to it.
Edit: add this section to Vagrantfile for the steps above:
config.vm.provision "shell", inline: <<-SHELL
if ! ifquery eth1 > /dev/null 2>&1; then
sudo echo "allow-hotplug eth1" >> /etc/network/interfaces
sudo echo "iface eth1 inet dhcp" >> /etc/network/interfaces
sudo ifup eth1
ip -4 a show dev eth1
fi
SHELL
At this point the vagrant vm should be accessible, able to access the web, able to access the hostonly network (other guests and the host through the configured ip, 192.168.178.1 in my case), these should all work:
ping 8.8.8.8 #web
ping 192.168.178.1 #host
ping 192.168.178.3 #other guest
Final result
Hopefully this enables all relevant communication for your use case also.

How can I access a vagrant guest from another virtualbox guest?

The scenario is that my dev environment is on a Vagrant box on my laptop (host) and I would like to do browser testing in a vitualbox vm, so I need to see one vm from another.
The vagrant box's port is :8080 which is forwarded to the host on the same port :8080. So I can see the server from the host at localhost:8080
Which address should I be using for the browser testing vm?
The testing vm's default gateway?
The vagrant vm's ip?
The host's virtual network ip?
And should I be using a NAT or host only adapter on the browser testing vm?
That makes for a lot of combinations, all of which I believe I have tried. What else do I need to understand here?
In your use case, you should be using Bridged networking (Public Network in Vagrant). If the VMs reside on the same host, you can even use internal (Private Network in Vagrant).
If using Public Network, the VM's 2nd NIC will be able to obtain an IP address from the DHCP server in your network (e.g. your home router).
Simply add the following code block in your Vagrantfile and do a vagrant reload
Vagrant.configure("2") do |config|
config.vm.network "public_network"
end
You should be able to get the IP address by using vagrant ssh and ifconfig / ip addr show.
In case you don't want to go with public_network just like me then you should do the steps below using private_network:
Open Vagrantfile from your project root
Search for config.vm.network
Add this line config.vm.network "private_network", ip: "192.168.33.10". Remember this is not the IP of your base machine it's a virtual-box IP address and your machine IP should be different. You can say it's a fake IP address so change it to anything else like 192.168.30.20.
Reload your vagrant using vagrant reload.
Now go to your other virtual guest in my case it's the Windows Guest 2. My base is Linux Mint Vagrant box is on Ubuntu Guest 1. Open C:\Windows\System32\drivers\etc\hosts file as admin and do the above IP's entry in there like 192.168.33.10 local.youralias.com. And save the file, after that you can now browse the site now at http://local.youralias.com/.
In case your guest 2 is also Linux just edit this file sudo vi /etc/hosts, and add this line at top of it 192.168.33.10 local.youralias.com. Now save and exit and browse the URL :)
Enjoy! Happy coding.
Adding to accepted answer, you can actually set IP and specify which network interface to use.
My setup on linux box via wifi and static IP:
You can find your wifi interface name by running ifconfig command.
Vagrant.configure("2") do |config|
config.vm.network "public_network", :bridge => 'wlp8s0', ip: "192.168.1.199"
end
This may have many source cause. In my case, I use vagrant fedora boxe.
I tried:
First using the private_network that I attached to a host only adapter and launched httpd service to test the connection between guest and host
config.vm.network "private_network", type: "dhcp", name: "vboxnet2"
config.vm.network "forwarded_port", guest:80, host:7070
but I was not able to ping my guest machine from the host and could no telnet the httpd service opened
Second using public_network and launched httpd service to test connectivity
config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", use_dhcp_assigned_default_route: true
I could ping my guest from my host but I could not telnet the httpd service.
For this two use case, the issue was that the port 80 on the fedora guest host was blocked by the firewall. Here is what fixed the issue and get all working for both privat_network and public_ntwork:
firewall-cmd --permanent --add-port 80/tcp #open the port permanently
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --list-port # list to check if the port was opened
systemctl stop firewalld # stop and open the firewall service
systemctl start firewalld
Old question, new answer: [disclaimer: i am not a vagrant expert]
both solutions might work but the solution in the "vagrant way of thinking" is that some component in your guest (rinetd?) should forward any requests to unknown ports to the host. From the host the request could then be mapped (via vagrant port forwarding) to a services that is running in the other guest.
So, to resume:
1.in guest-1 we do localhost:1234. Guest-1 will detect that this port is not available and forward to host
2. the host will check the vagrant port forwarding and forward to guest-2
3. in guest-2 we have some nice service listening to post 1234
4. done.

Boot2Docker private network setup

How can I do the private networking for the boot2docker docker container ?
For example, If I have a webapp, I can do the following in Vagrantfile
myapp1.vm.network "private_network", ip: "1.2.3.4"
myapp2.vm.network "private_network", ip: "1.2.3.5"
myapp3.vm.network "private_network", ip: "1.2.3.6"
Then I can use my browser to access my webapp at
http://1.2.3.4
http://1.2.3.5
http://1.2.3.6
How can I achieve the same result in docker easily ?
I also looked at How to expose docker container's ip and port to outside docker host without port mapping?
But in my boot2docker1.3, it said the interface eth0:1 does not exist
I looked at https://docs.docker.com/articles/networking
The tutorial does not work for boot2docker in mac.
Any help would be appreciated, thankyou!
I believe the instructions here, linked from this question give what you are looking for. The key is this line:
sudo route -n add 172.17.0.0/16 172.16.0.11
which tells your Mac how to route to the private network inside the VirtualBox VM that the Docker containers are on. (Obviously the specific addresses can change for your specific situation)
This still doesn't give you the ability to assign specific IP addresses to specific containers; as I said an add-on like weave can do that. (note: I work on weave)
You may also like this article which gives a beginner's overview of how Boot2Docker runs and illustrates how you have IP addresses inside the VirtualBox VM, and also an IP address of that box as a whole.

Using gitlab-vagrant-vm from OSX host

I followed the instructions here and was able to succesfully (I think) install the gitlab vagrant virtual machine on OSX 10.8 using virtualbox.
I can do vagrant up to get the VM running, and everything seems to work fine. After that I can do vagrant ssh without a problem. Also, after sshing into the VM I was able to do bundle exec rake gitlab:test, which completed with results being 1584 examples, 0 failures.
I would like to see the gitlab web interface from my OSX host machine. I thought I could just direct my browser to the IP indicated in the VagrantFile (http://192.168.3.14), but that didn't work.
Any ideas?
Also any other usage tips for this setup would be appriciated (things like where the repositories are stored on my host machine so I can back them up, if anyone set the gitlab-vagrant-vm up for external access from either another computer on the network or a remote source, ect.)
You have to connect a second interface for vagrant. To do this you've to edit the VagrantFile.
For example if you want to conenct to the host wifi add the following line after 192.168.3.14
config.vm.network :bridged, bridge: "en0: Wi-Fi (AirPort)"
You also can bridge to the ethernet interface. Use ifconfig on the host machine to determine the right interface. After that the dyndns-server of the host network will assign an IP to the Vagrant-Box. Then you can access GitLab on that IP.
Did you actually start the server? You can do that with
bundle exec foreman start -p 3000
This will start the server on port 3000, you would then access it from the host with
http://192.168.3.14:3000/
Hope this helps,
Chris

Vagrant not running on 33.33.33.10

The first time I started up vagrant, the VM was running on 33.33.33.10. After a "vagrant destroy", every time I start up vagrant it runs on 127.0.0.1 even though my Vagrantfile has the following configuration:
config.vm.network :hostonly, "33.33.33.10"
How do I get vagrant to run on 33.33.33.10 again?
127.0.0.1 is loopback interface's home address. Your current machine is always 127.0.0.1.
When you're looking for the proper IP address, run command ifconfig (on UNIX), and look for eth interface.
I guess it's still running at the same address, you just missed the correct IP.
Would you please try running ifconfig eth0 on your virtual machine?
HTH.

Resources