I’m trying to configure debugger for my web application, but I run into trouble with specifying correct ports for it.
Vagrantfile:
config.vm.network :private_network, ip: "192.168.68.8"
config.vm.network :forwarded_port, guest: 80, host: 8080
/etc/hosts (on my host machine)
192.168.68.8 mysite.com
I installed these two gems for debugging
gem 'ruby-debug-ide', group: [:development,:test]
gem 'debase', group: [:development,:test]
I read that in order to use ruby-debug-ide on vagrant, I should run
rdebug-ide --host 0.0.0.0 --port 80 --dispatcher-port 8080 -- bin/rails s
where --port
should be guest port from Vagrantfile and host port for `--dispatcher-port``
But it says
Permission denied - bind(2) for "0.0.0.0" port 80
On the other side, if I try to change those ports in Vagrantfile, I lose the opportunity to reach my application from 127.0.0.1:specified_port, but still can do it from mysite.com, which is confusing
you already have something listening on port 80 (apache or nginx) so you cant bind on this port. You can do one of the following
in your vagrant start rdebug-ide --host 0.0.0.0 --port 3000 --dispatcher-port 3000 -- bin/rails s
If you use a private network IP in your vagrantfile you dont need to forward port as you'll access your VM server using its own IP
run sudo netstat -nltp
in your VM, check the process which binds the port 80 and kill it
For example
vagrant@precise32:/etc/init.d$ sudo netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 512/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1827/apache2
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 652/sshd
tcp 0 0 0.0.0.0:58397 0.0.0.0:* LISTEN 539/rpc.statd
tcp6 0 0 :::111 :::* LISTEN 512/rpcbind
tcp6 0 0 :::22 :::* LISTEN 652/sshd
...
so you'll kill the apache2 process (PID 1827)