Access a Vagrant virtual host with xip.io

Submitted by christophe on Fri, 23/10/2015 - 15:19

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

  1. 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)
  2.  Add the xip.io domain on your Vagrant vm vagrant ssh on the Vagrant directory of your host sudo nano /etc/apache2/sites-available/localhost.conf and search your vhost to add the server alias ServerAlias my.local.site.192.168.X.X.xip.io
  3. 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
  4. 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

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.