How to browse to Vagrant VM site from other devices on local network? - vagrant

I'm running Laravel Homestead (Vagrant) on Windows 10.
I'd like to be able to use other devices on my LAN to test my Homestead site too. (My LAN also has a Mac and an iPhone.)
I found two ancient questions (1 and 2) that seem related to my goal, but I'm still stuck.
I've tried adding a public_network config to my Homestead.yaml according to the docs (https://laravel.com/docs/5.4/homestead#network-interfaces).
I've tried editing the homestead.rb file directly, too (but that didn't seem to help, so I reverted it).
My Homestead.yaml is:
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa2013
folders:
- map: c:/code/katievb-members
to: /home/vagrant/Code/katievb-members
sites:
- map: kvbmem.rcw
to: /home/vagrant/Code/katievb-members/public
schedule: false
databases:
- kvbmem
networks:
- type: "public_network"
ip: "192.168.1.104"
bridge: "Realtek RTL8811 Wireless LAN 802.11ac USB 2 Network Adapter"
My Windows machine is 192.168.1.104 on my LAN.
What should I change about my setup so that my Homestead website is browsable not just from the Windows machine that its on but also the other devices on the LAN?
And then what commands should I run before trying to browse to that site (http://kvbmem.rcw) on my iPhone? vagrant reload --provision?
(I have a DD-WRT router with DNSmasq if that will be helpful.)

The question you pointed gave you good hints so you need to enable bridge connection, in vagrant its public_network
If you want to assign a static IP, you cannot use the same IP of your windows machine, otherwise the other machine from your LAN will hit the servers running on the windows machine.
You want to select an IP reachable on your LAN in the same network of your windows machine so if your current IP is 192.168.1.104 you can use any of the 192.168.1.x that is available, for example
networks:
- type: "public_network"
ip: "192.168.1.100"
bridge: "Realtek RTL8811 Wireless LAN 802.11ac USB 2 Network Adapter"

Related

Homestead Running, SSH Works, But HTTP Connections Time Out

I'm having an issue with a homestead configuration that was previously running correctly. After reading some bad advice online regarding a separate issue, I accidentally wiped out my homestead.yaml by re-running init.bat, and have recreated the homestead config from memory the best I can. Most everything seems to be working - I can start the box successfully, and I can connect via SSH. My web root is mapped to the box correctly, as I can see all my project files on the box where I chose to map them. When I try to access the site via http (through the name I've mapped it to), I get a timeout. I've ensured that my hosts file has the update from myapp.app to 192.168.10.10, the same IP as in my homestead.yaml file. I will note, however, that when I ping 192.168.10.10 from the terminal, I also get a timeout.
Here's my Homestead.yaml:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: C:/Users/MyUsername/.ssh/id_rsa.pub
keys:
- C:/Users/MyUsername/.ssh/id_rsa
folders:
- map: C:/Users/MyUsername/Projects/myapp_laravel
to: /home/vagrant/code/myapp
sites:
- map: myapp.app
to: /home/vagrant/code/myapp/public
databases:
- homestead
Here's my hosts file:
192.168.10.10 myapp.app
I'll also note that I can successfully access my app via: http://localhost:8000/
I have also restarted my host machine since updating the hosts file, and reprovisioned the box.
Restarting the host machine again solved this for me.

How to setup Laravel Homestead server to run locally without being on a network/internet?

Previously, I manually setup my own VM on VirtualBox and configured it so it would also work when I'm coding offline (no internet/not connected to a router). I did this using settings in the VirtualBox GUI and also in Apache on the VM.
Now I'm interested in learning nginx and I've decided to try and use Laravel's Homestead. The tutorials I'm looking at seem to have the assumption I will be accessing the Homestead VM across the network (even though of course it's on the same PC). What do I need to do to ensure the VM will be accessible when I'm offline (like when I'm coding on a plane or train)? I'd like to still be able to have access to the internet from the VM whenever I do get back on WiFi (ie. for apt-get, etc.).
(note: My host machine is running Windows 7 64-bit)
Download and install fresh copies of Vagrant and Virtualbox.
https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2.msi
http://dlc-cdn.sun.com/virtualbox/4.3.22/VirtualBox-4.3.22-98236-Win.exe
Also download laravel/homestead manually
https://vagrantcloud.com/laravel/boxes/homestead/versions/0.2.2/providers/virtualbox.box
to my downloads folder C:\Downloads\homestead-0-2-2.box
After Installing Virtualbox and Vagrant. Installed laravel/homestead by running the following command in git bash (you can download git bash here: http://git-scm.com/downloads).
vagrant box add laravel/homestead /c/downloads/homestead-0-2-2.box
Run this command inside C:\users\yourusername
git clone https://github.com/laravel/homestead.git Homestead
NB: This will create this folder: C:\Users\yourusername\Homestead
With some files.
Still in Git bash, cd into C:\Users\yourusername\Homestead and run this command:
bash init.sh
NB: this will create a folder C:\Users\yourusername\.homestead that contains Homestead.yaml and some other files
Then Generate an SSH key which you will need when you want to login to your VM by running this command:
ssh-keygen -t rsa -C "youremailaddress#youremail.com"
NB: This will ask some question simply hit enter or type yes and hit enter.
This will create your ssh key inside C:\Users\yourusername\.ssh
Then you need to configure homestead by editing for Nginx
C:\Users\digitlimit\Homestead\Homestead.yaml
You can right-click Homestead.yaml file then click open then choose to open with wordpad.
My Homestead.yaml looks this after editing:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /wamp/www
to: /home/vagrant/Code
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
# blackfire:
# - id: foo
# token: bar
NB: To understand the mapping which is a process of sharing a folder between the host and the VM:
My laravel project is located at C:\wamp\www\laravel
This directory /home/vagrant/Code will be inside the VM after installation.
So what am telling VM is, whenever you see /home/vagrant/Code reference this folder C:\wamp\www\laravel
Also in this:
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
What we are saying here is when i go to my browser and type http://laravel.dev display the content of /home/vagrant/Code/laravel/public which is actually pointing to C:\www\wamp\laravel\public
After editing Homestead.yaml file save your chnages
NB: Before we can use http://laravel.dev in the host web browser to view our laravel project, we need to add this the following to the hosts file located in
C:\Windows\System32\drivers\etc\hosts
Add this ip address under the list of other ip address listed if any:
192.168.10.10 laravel.dev
Finally, go back to your Git bash, ensure you are in
/c/Users/yourusername/homestead and type:
vagrant up
Wait for vagrant to complete its processes. Click yes when you see any dialog box asking for permission to create network adapter on your system
Any VM running on your development machine will be accessible when you're offline. Just make sure you setup your development machine's host file to have the VM's location set.
If you're following the Laravel Homestead Setup:
In scripts/homestead.rb, you'll have a line that has the IP Address of the VM.
# in scripts/homestead.rb
# Configure A Private Network IP
config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"
Add this IP address into to your hosts file. This is located usually in C:\Windows\System32\drivers\etc\hosts
#in hosts file
192.168.10.10 yourwebsite.dev

How can I access a vagrant guest from another virtualbox guest?

The scenario is that my dev environment is on a Vagrant box on my laptop (host) and I would like to do browser testing in a vitualbox vm, so I need to see one vm from another.
The vagrant box's port is :8080 which is forwarded to the host on the same port :8080. So I can see the server from the host at localhost:8080
Which address should I be using for the browser testing vm?
The testing vm's default gateway?
The vagrant vm's ip?
The host's virtual network ip?
And should I be using a NAT or host only adapter on the browser testing vm?
That makes for a lot of combinations, all of which I believe I have tried. What else do I need to understand here?
In your use case, you should be using Bridged networking (Public Network in Vagrant). If the VMs reside on the same host, you can even use internal (Private Network in Vagrant).
If using Public Network, the VM's 2nd NIC will be able to obtain an IP address from the DHCP server in your network (e.g. your home router).
Simply add the following code block in your Vagrantfile and do a vagrant reload
Vagrant.configure("2") do |config|
config.vm.network "public_network"
end
You should be able to get the IP address by using vagrant ssh and ifconfig / ip addr show.
In case you don't want to go with public_network just like me then you should do the steps below using private_network:
Open Vagrantfile from your project root
Search for config.vm.network
Add this line config.vm.network "private_network", ip: "192.168.33.10". Remember this is not the IP of your base machine it's a virtual-box IP address and your machine IP should be different. You can say it's a fake IP address so change it to anything else like 192.168.30.20.
Reload your vagrant using vagrant reload.
Now go to your other virtual guest in my case it's the Windows Guest 2. My base is Linux Mint Vagrant box is on Ubuntu Guest 1. Open C:\Windows\System32\drivers\etc\hosts file as admin and do the above IP's entry in there like 192.168.33.10 local.youralias.com. And save the file, after that you can now browse the site now at http://local.youralias.com/.
In case your guest 2 is also Linux just edit this file sudo vi /etc/hosts, and add this line at top of it 192.168.33.10 local.youralias.com. Now save and exit and browse the URL :)
Enjoy! Happy coding.
Adding to accepted answer, you can actually set IP and specify which network interface to use.
My setup on linux box via wifi and static IP:
You can find your wifi interface name by running ifconfig command.
Vagrant.configure("2") do |config|
config.vm.network "public_network", :bridge => 'wlp8s0', ip: "192.168.1.199"
end
This may have many source cause. In my case, I use vagrant fedora boxe.
I tried:
First using the private_network that I attached to a host only adapter and launched httpd service to test the connection between guest and host
config.vm.network "private_network", type: "dhcp", name: "vboxnet2"
config.vm.network "forwarded_port", guest:80, host:7070
but I was not able to ping my guest machine from the host and could no telnet the httpd service opened
Second using public_network and launched httpd service to test connectivity
config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", use_dhcp_assigned_default_route: true
I could ping my guest from my host but I could not telnet the httpd service.
For this two use case, the issue was that the port 80 on the fedora guest host was blocked by the firewall. Here is what fixed the issue and get all working for both privat_network and public_ntwork:
firewall-cmd --permanent --add-port 80/tcp #open the port permanently
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --list-port # list to check if the port was opened
systemctl stop firewalld # stop and open the firewall service
systemctl start firewalld
Old question, new answer: [disclaimer: i am not a vagrant expert]
both solutions might work but the solution in the "vagrant way of thinking" is that some component in your guest (rinetd?) should forward any requests to unknown ports to the host. From the host the request could then be mapped (via vagrant port forwarding) to a services that is running in the other guest.
So, to resume:
1.in guest-1 we do localhost:1234. Guest-1 will detect that this port is not available and forward to host
2. the host will check the vagrant port forwarding and forward to guest-2
3. in guest-2 we have some nice service listening to post 1234
4. done.

Homestead 2.0, Vagrant and VirtualBox running a lot slower than MAMP

I've just setup Homestead 2.0 vagrant server for Laravel 5 running on VirtualBox on OSX 10.10 (Yosemite) and it's running a lot slower than MAMP.
I really want to use Homestead, but the 1-3 second delay in loading pages is becoming really annoying, yet every load request is instant on MAMP.
Am I missing something on my setup?
Homestead.yaml:
---
ip: "192.168.10.10"
memory: 2048
cpus: 2
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /Users/jackbarham/Code
to: /home/vagrant/Code
sites:
- map: tasks.mac
to: /home/vagrant/Code/tasks/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
hosts:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
192.168.10.10 tasks.mac
127.0.0.1 tasks-mamp.mac # MAMP PRO - Do NOT remove this entry!
I asked the same question on reddit/r/laravel and got the answer:
Locate the homestead.rb file in: /Users/username/.composer/vendor/laravel/homestead/scripts
Shut down the VM (homestead halt)
Open homestead.rb file, on line 49, under "# Register All Of The Configured Shared Folders" change:
from:
settings["folders"].each do |folder|
config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil
end
to:
settings["folders"].each do |folder|
config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil, :nfs => true
end
config.vm.network "private_network", type: "dhcp"
Power up (homestead up) and this should speed things up
Source: http://www.reddit.com/r/laravel/comments/2vvama/homestead_20_vagrant_and_virtualbox_running_a_lot
In my case using Windows as HOST is the same, it is because VirtualBox uses vboxsf as a file system to mount files from host to guest, I don't know why but it is too slow.
On the GUEST (Ubuntu 16.04) I mounted the working folder as a Network Folder using CIFS and runs a lot more faster.
On the guest side I use this: https://wiki.ubuntu.com/MountWindowsSharesPermanently
On the Host side (mac) I think you should follow this instructions: https://support.apple.com/kb/PH18707?locale=en_US

vagrant homestead - public network not working on osx

I've been trying all day to get a public network setup using Vagrant 1.6.5 with VirtualBox. I really need to be able to access all my Homestead sites on my other devices (iPad, iPhone, Android phone, etc.) on my local network. The box provisions fine but the sites all timeout.
homestead.rb
config.vm.network "public_network", :bridge => "en0: Wi-Fi (AirPort)", :ip => "192.168.1.200"
My host is OS X mavericks using DHCP (192.168.1.137).
Private networking works fine, but I can't get public networking to work with any variation of the above config.
You can just grab the host's internal IP address (NOT the VM ip) and add the port :8000. Let's say your host ip is 192.168.0.5, then from any other device on your network, you can just browse to the host at 192.168.0.5:8000 and you'll hit the VM and see the Laravel home page.
This works great for me with the default homestead.rb setting:
# Configure A Private Network IP
config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"
To get my homestead machine to be visible from my LAN I did the following:
Edit the Homestead/scripts/homestead.rb file and set config.vm.network :public_network, ip: "192.168.1.123" (just make sure the IP is free).
Do a vagrant reload
Make sure my old local hosts file now points to the new IP.
The result is I can ping 192.168.1.123 from another machine in my LAN.
What is the error that you are getting? Make sure that 192.168.1.200 is not being used by any other device.
Network configuration for vagrant boxes
This row works fine for me:
config.vm.network :public_network, ip: settings["ip"] ||= "192.168.10.10", bridge: "eth0"
Then it uses the ip variable from ~/.homstead/Homestead.yaml and if thats not set it uses 192.168.10.10

Resources