Search code examples
virtual-machinevagrantvagrantfilepuphpet

Vagrant is not port forwarding with VirtualBox and PuPHPet


Problem

I cannot connect to my virtual machine's environment, despite using an accepted private network and forwarded ports.

Description

System

Upon vagrant up, I vagrant ssh into my virtualbox. The following request work as expected:

[06:04 PM]-[vagrant@precise64]-[~]
$ curl -v 192.168.56.101
* About to connect() to 192.168.56.101 port 80 (#0)
*   Trying 192.168.56.101... connected
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: 192.168.56.101
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 09 Jul 2014 18:05:05 GMT
< Server: Apache/2.4.9 (Ubuntu)
< Vary: Accept-Encoding
< Content-Length: 481
< Connection: close
< Content-Type: text/html;charset=UTF-8
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Index of /</title>
 </head>
 <body>
<h1>Index of /</h1>
  <table>
   <tr><th valign="top"><img src="/icons/blank.gif" alt="[ICO]"></th><th><a href="?C=N;O=D">Name</a></th><th><a href="?C=M;O=A">Last modified</a></th><th><a href="?C=S;O=A">Size</a></th><th><a href="?C=D;O=A">Description</a></th></tr>
   <tr><th colspan="5"><hr></th></tr>
   <tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
* Closing connection #0

[06:05 PM]-[vagrant@precise64]-[~]
$ curl -v playworldsystems.dev
* About to connect() to playworldsystems.dev port 80 (#0)
*   Trying 192.168.56.101... connected
> GET / HTTP/1.1
> User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: playworldsystems.dev
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 09 Jul 2014 18:05:52 GMT
< Server: Apache/2.4.9 (Ubuntu)
< X-Powered-By: PHP/5.5.14-2+deb.sury.org~precise+1
< Vary: Accept-Encoding
< Content-Length: 122
< Connection: close
< Content-Type: text/html
<
<pre class='xdebug-var-dump' dir='ltr'><small>string</small> <font color='#cc0000'>'hello'</font> <i>(length=5)</i>
* Closing connection #0
</pre>

However, when I try both commands from within my HOST terminal, I receive the following error:

curl -v 192.168.56.101
* About to connect() to 192.168.56.101 port 80 (#0)
*   Trying 192.168.56.101...
* Adding handle: conn: 0x7fc6f1000000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fc6f1000000) send_pipe: 1, recv_pipe: 0
* Failed connect to 192.168.56.101:80; Operation timed out
* Closing connection 0
curl: (7) Failed connect to 192.168.56.101:80; Operation timed out
☁  ~  curl -v playworldsystems.dev
* Adding handle: conn: 0x7fdbe9803000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fdbe9803000) send_pipe: 1, recv_pipe: 0
* About to connect() to playworldsystems.dev port 80 (#0)
*   Trying 192.168.56.101...
* Failed connect to playworldsystems.dev:80; Operation timed out
* Closing connection 0
curl: (7) Failed connect to playworldsystems.dev:80; Operation timed out

Even after trying cURLing from both port 6969 and 8080, I still have no success. I've used random IP Addresses as well as Ports. I've tried altering my virtual host to other port numbers. Nothing seems to work. I will mention that when first starting out, I noticed that this vagrant setup has worked --both only twice. Each time it was working, i would vagrant suspend and vagrant up the next morning to find that my prior solution is no longer working.

Perhaps this fact is what makes this process so frustrating. I want to get of MAMP for my current projects but fear that it is either my work machine's settings that are interfering or perhaps some other application or network related issue. I'm unsure what steps to take and am looking forward to any and all solutions.


Solution

  • a few tips/pointers.

    1. check that the firewall rules are not blocking the ports, if all else fails, just disable it for testing "iptables -F"
    2. make sure ports are forwarded correctly https://docs.vagrantup.com/v2/networking/forwarded_ports.html so what you want for http is host:8080 guest:80
    3. sometimes your IP address changes on your host ( for example, acquiring new dhcp or joining new network home/work/vpn )
      check that you can ping your VM guest from your host via the correct IP from the correct adapter. On the host run "ifconfig -a" (on the mac there should be some en0 for ethernet and en1 for airport) if you can ping the vm guest, then you can hit the web server via port 8080 ( http://mylocal.dev:8080/ ) provided of course that you edited your /etc/hosts to point your vhost to the above mentioned IP address.