Access a Vagrant virtual host with

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. or via another device than the host environment (smartphone, tablet, ...).

Vagrant allows you to quickly deploy dev environments on a Virtualbox VM. 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 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, you should have something like 192.168.X.X on a class C LAN (
  2.  Add the 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
  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. "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

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.