Accessing Homestead/Vagrant site from different device on same network

Published 3 years ago by JosephusPaye

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.

Best Answer (As Selected By JosephusPaye)
5pArxz

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

5pArxz
5pArxz
3 years ago (52,550 XP)

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

henrique

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.

5pArxz
5pArxz
3 years ago (52,550 XP)

@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

henrique

@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

5pArxz
5pArxz
3 years ago (52,550 XP)

@henrique yeah you're right :) haha :P

carkis
carkis
3 years ago (49,400 XP)

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.

JosephusPaye

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

clarkeash

What about using vagrant share ?

Shovels

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!!

SP1966
SP1966
3 years ago (14,975 XP)

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?

freekmurze

The key to do this is to specify a public_network in your Vagrant/Homestead configuration.

You can see the relevant line here in my customized Homestead box.

JosephusPaye

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
5pArxz
3 years ago (52,550 XP)

@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

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.

bashy
bashy
3 years ago (996,910 XP)

@hettiger That is probably the worst way possible :P

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

Please sign in or create an account to participate in this conversation.