This tip is for people that would access a Vagrant dev website from another VM (let's say to test another version of Internet Explorer via e.g. https://github.com/xdissent/ievms) or via another device than the host environment (smartphone, tablet, ...).
Vagrant allows you to quickly deploy dev environments on a Virtualbox VM.
xip.io will let you access your dev website from other devices (already tried to patch /etc/hosts on an iPad?)
Basically, there is no problem to access your dev server from xip.io if your Apache is hosted directly on your Mac / PC.
This is something else if you use a VM for the LAMP stack.
Follow these steps to tackle this
- Fetch your local IP (via ifconfig an *nix or ipconfig on Windows), this is needed for xip.io, you should have something like 192.168.X.X on a class C LAN (https://en.wikipedia.org/wiki/Private_network)
- Add the xip.io domain on your Vagrant vm
vagrant ssh
on the Vagrant directory of your hostsudo nano /etc/apache2/sites-available/localhost.conf
and search your vhost to add the server aliasServerAlias my.local.site.192.168.X.X.xip.io
- Add a port forwarding on the Vagrantfile by adding this line on the # Configure forwarded ports. section any free port is valid, let's use 4567.
config.vm.network "forwarded_port", guest: 80, host: 4567, protocol: "tcp", auto_correct: true
- Restart vagrant on your host VM directory
vagrant halt vagrant up
Now you can access your dev site from any device, VM with my.local.site.192.168.X.X.xip.io:4567/optional_path
Comments
Anonymous (not verified)
Thu, 19/01/2017 - 17:38
Permalink
Thanks for this, it was just…
Thanks for this, it was just what I was looking for.
Add new comment