Vagrant + Xdebug + Atom - vagrant

I have a vagrant box with xdebug installed, running on OSX, but Im struggling to get the Atom xdebug plugin (php-debug) to connect to it.
I pasted the phpinfo(); data into the xdebug validation site and it said all was good. And you can see all the xdebug settings.
I have mapped port 9000 in the vagrant file.
config.vm.network :forwarded_port, guest: 9000, host: 9000
The vagrant box has host only network that exposes 192.168.10.100 as the IP of the server.
And I've tried all manner of different xdebug options, the ones on the ATOM plugin site suggest..
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true
But that is a slightly confusing as remote_connect_back=1 means xdebug will ignore the remote_host setting - so not sure why both are in there - neither work.
I've restarted apache / php after each time I change the options, and check they are loaded with phpinfo();
If I check who is listening on port 9000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Atom\x20H 10656 Matt 28u IPv6 0x321cb0a96ba5b593 0t0 TCP *:cslistener (LISTEN)
VBoxHeadl 10889 Matt 19u IPv4 0x321cb0a981a71433 0t0 TCP *:cslistener (LISTEN)
You can see both vagrant (virtual box) and Atom. Although Atom is IPv6 which is odd....
But enabling the debugger in ATOM, setting a breakpoint and hitting the site, nothing happens - ATOM never connects.
Any ideas? Anyone got this to work?

But that is a slightly confusing as remote_connect_back=1 means xdebug will ignore the remote_host setting
You are correct -- that option is not needed there -- it better be set to 0
xdebug.remote_host=127.0.0.1
This is wrong (unless you will be doing debugging via SSH tunnel). It must be an IP where debug client (Atom in your case) is running. It's xdebug who connects to client and NOT other way around: https://xdebug.org/docs/remote
This also means that the IP must be as seen from that Vagrant machine. Possibly the easiest way of getting it -- look at what $_SERVER['REMOTE_ADDR'] has.
I have mapped port 9000 in the vagrant file.
config.vm.network :forwarded_port, guest: 9000, host: 9000
You do not need to expose 9000 port in Vagrant -- nobody will be connecting to it (like you do with port 80 for web server) -- it's xdebug from VM/guest OS will be connecting outside to your "real"/host OS.
If anything -- you should be allowing outgoing connections on that port instead of incoming.
If I check who is listening on port 9000
This one means that Atom is unable to receive incoming xdebug connection over TCPv4 .. which xdebug will try to use by default (unless you specify IPv6 address in xdebug.remote_host).
If anything -- collect xdebug log (xdebug.remote_log) and see where it tries to connect etc.

#LazyOne already answered this question, but issue I had was caused by antivirus (MCAfee) which was blocking incoming traffic. Maybe this will help someone in the future.

Related

Vagrant - vagrant cannot forward the specified ports on this VM

When i run vagrant up i get the following error:
Vagrant cannot forward the specified ports on this VM, since they
would collide with another VirtualBox virtual machine's forwarded
ports! The forwarded port to 3306 is already in use on the host
machine.
To fix this, modify your current projects Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.forward_port 80, 1234
I checked and i don't have any processes using port 3306 locally.
I also tried vagrant destroy and vagrant up, didn't help.
vagrant suspend followed by vagrant resume didn't help as well.
What else could be the issue?
What's your command to find the port?
Maybe you can see this. Vagrant Port Collision on Port 80, but Port 80 is not Forwarded in the VagrantFile
Turns out there was a process on my machine running on port 3306.
Running lsof -i :3306 didn't show it, only when i used sudo it did.

vagrant ports report in use after reload

I have a few vagrant VMs (both on Mac and windows, all running linux). I have port forwarding defined like this in the Vagrant file:
config.vm.network "forwarded_port", guest: 80, host: 9007
The first time I do a vagrant up it works fine. But then when I do a vagrant reload or vagrant halt followed by vagrant up I get this message:
Vagrant cannot forward the specified ports on this VM, since they
would collide with some other application that is already listening
on these ports. The forwarded port to 9007 is already in use
on the host machine.
To fix this, modify your current project's Vagrantfile to use another
port. Example, where '1234' would be replaced by a unique host port:
config.vm.network :forwarded_port, guest: 80, host: 1234
Sometimes, Vagrant will attempt to auto-correct this for you. In this
case, Vagrant was unable to. This is usually because the guest machine
is in a state which doesn't allow modifying port forwarding. You could
try 'vagrant reload' (equivalent of running a halt followed by an up)
so vagrant can attempt to auto-correct this upon booting. Be warned
that any unsaved work might be lost.
Then I have to change the port to bring up the VM, which is a pain. I have checked with netstat and lsof, and nothing seems to be using the port. I though it was perhaps a timing issue, and after a while I could use the port, but even after waiting many hours I still get the error.
This happens in both the Mac and Windows environments. Is there some setting that would allow me to reuse the ports?
I generally use static IP to avoid issues with port forwarding. Vagrant has an auto_correct feature to help fix that.
from vagrant forwarded port docs
It is common when running multiple Vagrant machines to unknowingly
create forwarded port definitions that collide with each other (two
separate Vagrant projects forwarded to port 8080, for example).
Vagrant includes built-in mechanism to detect this and correct it,
automatically.
Port collision detection is always done. Vagrant will not allow you to
define a forwarded port where the port on the host appears to be
accepting traffic or connections.
Port collision auto-correction must be manually enabled for each
forwarded port, since it is often surprising when it occurs and can
lead the Vagrant user to think that the port was not properly
forwarded. Enabling auto correct is easy:
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 80, host: 8080,
auto_correct: true
end
The final :auto_correct parameter set to true tells Vagrant to auto
correct any collisions. During a vagrant up or vagrant reload, Vagrant
will output information about any collisions detections and auto
corrections made, so you can take notice and act accordingly.

Empty reply from server - can't connect to vagrant vm w/port forwarding

I'm running werkzeug (as part of a Tilestache setup) inside a Vagrant VM, running ubuntu 'precise.'
In my Vagrantfile, I have:
config.vm.network :forwarded_port, guest: 8080, host: 8080
When I start the server in the VM, I see:
* Running on http://127.0.0.1:8080/
If I curl that address from within the VM, I get the expected result. When I curl it from the host machine, I get:
curl: (52) Empty reply from server
And Chrome says "No data received."
Troubleshooting info:
The server responds to pings from the host machine
a port sniffer verifies that the port is open
running netstat -ntlp | grep 8080 in the vm shows that the server is listening on 8080
My local hostsfile doesn't have any weird conflicts
I'm also forwarding 22 => 2222, and I can ssh in with no trouble
I've disabled the firewall on the host, and i don't believe there's one on the guest (iptables and ufw are disabled, at least)
I've set auto_correct: true in case there are conflicts (there aren't)
I know I could set up a private network, but I'd like to understand why this isn't working and how to troubleshoot it.
Any other ideas?
When running a server from within a VM, start the server on 0.0.0.0 instead of 127.0.0.1.
127.0.0.1 is only accessible to the local machine, which for a VM means nothing outside of the VM can reach it! 0.0.0.0 is accessible from anywhere on the local network, which to a VM includes the host machine.
The answer came from here: Connection Reset when port forwarding with Vagrant
(Which apparently got its answer from here: https://stackoverflow.com/a/5999945/738675)
With help from: https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1
Google-bait:
Here are the errors you might receive if this is the problem:
Chrome: "No data received"
Firefox: "The connection was reset - The connection to the server was reset while the page was loading."
Safari: "Safari can’t open the page [URL] because the server unexpectedly dropped the connection"
curl: "Empty reply from server"
In the /etc/hosts inside the VM, change line
127.0.0.1 localhost -> 0.0.0.0 localhost
and then restart server
This can also be a problem with your firewall on the vagrant machine. If you can curl the address while on the vagrant box, then check your firewalld settings or turn it off:
on CENTOS:
sudo service firewalld stop
Then you should update your firewalld settings and restart it ;)

Vagrant port forwarding not working on Mavericks

I'm using a vagrant Geodjango box and port forwarding is not working for me.
On the box, I have run:
python manage.py runserver 0.0.0.0:8000
But http://localhost:8000 and http://localhost:4567 both find nothing on the host machine.
On the Vagrant box, curl -v 'http://localhost:8000/' gives the usual:
<h2>Congratulations on your first Django-powered page.</h2>
which suggests that Django is running okay. But on the host machine, trying curl -v 'http://localhost:8000/' gives the following output:
curl: (7) Failed connect to localhost:8000; Connection refused
My Vagrantfile has the following port forwarding set up:
config.vm.forward_port 8000, 4567
Disabling the Mac's firewall does not help and stopping Apache makes no difference. I have tried running lsof -i :8000 on the host machine and there is no output, so I figure nothing is using the port.
Can anyone suggest anything?
I had the same issue on Yosemite and none of the ports were forwarding. Disabling the Firewall filter on the guest machine helped:
sudo service iptables stop
Good to see you figured it out yourself.
Just want to add my 2 cents, in V2 Vagrantfile, the port forwarding code block is like below, try to use the new ones so as to avoid port conflicts (back in v1 I always got confused which is which).
config.vm.forward_port 8000, 4567 is forwarding guest port 8000 to host 4567, not the other way around.
In V2 format, it looks like below, which is clearer from my opinion
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 80, host: 8080
end

Vagrant Port Forwarding on Mac OS X Lion

I've been struggling trying to connect to a centos 6.4 vm using Vagrant.
I'm using salt as a provisioning agent and I have installed apache,php,mysql packages successfully.
When i ssh into the box apache is running fine. I added an index.html file in /var/www and I get the contents back when I curl localhost:80
Vagrant.configure("2") do |config|
## Chose your base box
config.vm.box = "centos63"
config.vm.box_url = ""
## For masterless, mount your salt file root
config.vm.synced_folder "salt/roots/", "/srv/"
## Use all the defaults:
config.vm.provision :salt do |salt|
salt.verbose = true
salt.run_highstate = true
salt.minion_config = "salt/minion"
end
end
Vagrant::Config.run do |config|
config.vm.forward_port 80, 8080
config.vm.share_folder "mypath", "/var/www/leo", "."
end
I ran sudo lsof -i :8080 on my local machine and gave me no results. I also cleared the iptable config in the guest machine with iptables -F. When I curl the guest machine
curl -v 'localhost:8080'
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* Connection refused
* Trying fe80::1...
* Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host
Do I need guest additions installed? I looked around on how to install this but I'm not sure if it has to be installed on the host or the guest. Not sure what else to try.
What you are trying to do here isn't possible just using vagrant without running vagrant as root. You can run Vagrant as root i believe but VirtualBox won't agree with that. You can continue to use a port number or if you want or need to use port 80 there is a way.
I had this issue when a client of mine asked me to do a Wordpress Multisite setup. With Wordpress MS you can't have port numbers in the URL b/c some of the URL mapping will not work correctly. I was surprised when I found that out and didn't want to go back to using a program like MAMP.
Anyway here are two ways to achieve this goal (neither are very hard). I'm a Mac user so these are Mac specific Answers, I will see if there is a Windows version and update my answer when I can test it to make sure (see below, there is a way).
Way #1 (Mac IP Firewall Utility):
In your vagrant file
config.vm.forward_port 80, 8080
config.vm.forward_port 443, 8443
Thats pretty normal.
Now open up terminal and you can use the ipfw utility
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to me 80
sudo ipfw add 101 fwd 127.0.0.1,8443 tcp from any to me 443
Now that cmd is not permanent so you would have to re-run the cmd if you restarted your machine. You can make it permanent though and I am including a link below that will explain the rest of way #1.
Web Development on Port 80 and 443 in Vagrant
Way #2 (Mac POW and Anvil):
If you don't have Pow yet, get it! It's a really cool app.
Install Pow and Anvil, you can find Anvil there and you can find Pow there.
You can read the docs on how to set those up but don't pay attention to the "static" and "rack" sites part, you need this part.
You will be using Port Proxying through Pow to take the incoming traffic from mycoolsite.dev and forward it to the virtual machine like mycoolsite.dev:8080 and then the virtual machine will forward 8080 to 80 and back up the line your content will come.
After you install Anvil/Pow and get them set up run this line:
echo 8080 > ~/.pow/mycoolsite
Then click Anvil in the task bar (you may have to refresh it or close and reopen) and turn the site on, thats it, what?? Really? Pow and Anvil rock!!
So there are two ways I have found, I'm sure that there are some things you can do with your Hosts file and I used to do that a bunch. However, these other ways that are available really make it easy to forget about that pesky hosts file.
Note for Windows Users (and Mac users that don't like the first 2 ways): You can use Vagrant Host Manager, you can find out how to set it up here on github. It is a vagrant plugin and basically will edit your hosts file for you, all you do is your vagrantfile config and you are good to go after that. I just tested it on Windows 7 and it worked there so it should be good, if you have any issues just look through the docs on github or file an issue for the Vagrant Host Manager team to review.
I changed the guest port to 5656 and it worked. When running lsof -i :8080 I didn't see any results so i figured nothing was using that port maybe I was wrong.

Resources