JosephusPaye's avatar

Accessing Homestead/Vagrant site from different device on same network

I am working on a mobile optimized site and want to test my designs on a mobile phone, but when I enter the IP address of my development machine (Windows) into my phone's browser, I cannot get to the Homestead/Vagrant site. Also trying the Vagrant IP address doesn't help either, with or without the port included. I tried this approach because that's how I did it when I was using WAMP/XAMPP.

I've tried a few Google searches but can't find anything to help. Does anyone have any ideas on how I could do this?

I am a newbie and this is my first post here, so please consider me if there is something obvious I'm missing.

Thanks in advance.

0 likes
23 replies
5pArxz's avatar
5pArxz
Best Answer
Level 16

in this example my app is called myapp and my notebooks network address is : 192.168.0.4

Where you reference your app in your hosts file you can just add another line like this:

127.0.0.1 myapp.app

192.168.0.4 myapp.app

and access it on another device on the network like this : 192.168.0.4:8000

11 likes
henrique's avatar

Also keep in mind that sometimes Firewalls/Anti-virus can give a hard time on this, blocking the access without notice. I believe the VM firewall wouldn't block this, but windows firewall or anti-virus could, try disabling everything for some minutes and testing again, if it works you can enable it back and add an exception.

1 like
5pArxz's avatar

@henrique with just a standard windows install over local network only it shouldn't be a problem. at least in the last couple of years i've never experienced that issue. i did however have such an issue when making it public. but in that case it was the router that was refusing the connection :) but that is a whole other story

1 like
henrique's avatar

@5pArxz yeah, but we don't know what software he have installed, right? :)

Anyways, let's not transform his thread in a discussion about firewalls, he asked a question and I said one possibility, as I said "firewalls/ANTI-VIRUS CAN", so it's not only firewalls and it's not a certain thing :P

1 like
carkis's avatar

What type of network adapter does your VM has? Assuming you are using homestead I know it uses a NAT adapter with port forwarding. In that case just make sure the http forwarded port is open in your firewall.

If that doesn't work, just try disabling the firewall and/or antivirus just as @henrique said.

If the VM is using a Host-only adapter you'll have a hard time trying to reach it from outside.

One neat way to avoid all that hassle is using a bridged adapter to the ethernet interface. That way the VM is just like any other physical device on your network.

1 like
JosephusPaye's avatar

Thanks for all the input guys. I'll try out your suggestions and let you know what worked for me.

Shovels's avatar

Sounds like it's possibly the firewall. Windows by default will block the inbound ports, so you need to open up a range.

If you're testing on various screen sizes definitely check out http://www.browsersync.io/

You can run it as a gulp task and it creates a proxy address which you can point loads of devices at - All your interactions, clicks, scrolls, etc are mirrored in real-time across all devices. It's the dogs danglers!!

1 like
SP1966's avatar

I've tried @5pArxz's advice and I get "No Input File Specified". I've tried it with the firewall off and on with no change. I'm on a Mac with 10.9.4, anybody have any further ideas?

JosephusPaye's avatar

I tried @5pArxz's code and it works. Thanks guys. Is it possible to access multiple Homestead/Vagrant sites using this method (adding the lines to the host file)? Not essential, I just want to know.

Thanks again for the help.

5pArxz's avatar

@SP1966 Glad you got it working :) and honestly i've not tried that yet and i don't believe it will work the same

hettiger's avatar

I currently use this approach:

##
# Homestead
#
# Homestead is the virutal machine running all local
# web development applications. It's domains need to
# be registered here one by one.
##
192.168.10.10    workbench-one.dev
192.168.10.10    workbench-two.dev

##
# External Testing
#
# Route the network cards IP address to the Homestead
# virtual machine so you can access it using port 8000.
##
192.168.1.6    192.168.10.10

(192.168.1.6 is my network cards IP address)

Now if i want to test workbench-two.dev on a smartphone for example i change following line in its nginx site config

listen 80;

to

listen 80 default_server;

Once done all i need to do is

sudo service nginx reload

If i browse 192.168.1.6:8000 from my smartphone i'll get to see the contents of workbench-two.dev. Of course you must remove default_server once you're done. If you have this on multiple configuration files, you'll run into trouble.

7 likes
bashy's avatar

@hettiger That is probably the worst way possible :P

Use something like http://xip.io and change the subdomain part for different sites...

1 like
hettiger's avatar

@bashy looks promising thank you.

Well i think my approach is not all that bad because it works, and it works even if you have no internet connection or when xip.io is down. ;-)

1 like
barnabas.kecskes's avatar

@bashy - the best approach is usually defined by the requirements and by nothing else :)

I only wanted some quick testing on mobile, so @hettiger 's approach was all fine - all I needed to do is to set which application will load when accessing the IP address on my mobile browser and specifying the default amongst many in nginx setup did the trick and it couldn't have been any easier, so for my case this was the perfect solution. :)

bashy's avatar

Can get the same result but with much cleaner and easier configuration just by adding in a a forwarded port and another domain into the server_name. No need to change it to default_server just for that :)

Mario Nava's avatar

Hi everybody,

I'm having the same trouble and this solutions almost works for me. The situation is that I have several sites on my homestead.yaml and when I go to my local IP, only shows one of this sites. How can I choose the site that I need to review?

Before hands thank you!

benbowler's avatar

@5pArxz Good solution, you don't actually need to update the hosts file for that to work. You can just hit [LOCAL NETWORK IP]:8000. Easy :)

Please or to participate in this conversation.