Skip to content

Instantly share code, notes, and snippets.

@stephan281094
Last active October 25, 2016 22:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stephan281094/4d3bb29324f97f57e902 to your computer and use it in GitHub Desktop.
Save stephan281094/4d3bb29324f97f57e902 to your computer and use it in GitHub Desktop.
Using Vagrant Share with multiple sites

Using Vagrant Share with multiple sites

Vagrant Share is a great feature that's quite handy to demo your application to clients. It basically allows you to share whatever you run locally on your VM, accessible by anybody who is connected to the internet. However, Vagrant Share doesn't support multiple domains pointing to different applications on your virtual machine. Unless you use different ports. This document will teach you how to set your virtual machine up to allow sharing multiple projects with Vagrant Share.

Note: This document is primary based on a virtual machine running Apache.

The setup

  1. Create a free account at HashiCorp's Atlas.
  2. Login using vagrant login.
  3. SSH into the virtual machine using vagrant ssh.
  4. Inside /etc/apache2/sites-available/ edit your virtual hosts by changing the port to something else (say :81). Unfortunately Vagrant Share doesn't allow you to use HTTPS, so changing the 443 port is practically useless.
  5. Inside /etc/apache2/ports.conf add Listen 81 right under Listen 80.
  6. Restart the server: sudo service apache2 restart

Sharing

In the terminal on your host machine enter the following:

  1. vagrant share --http 80
  2. vagrant share --http 81

This will create two links for you looking like http://something-random-1234.vagrantshare.com/.

Common problems

Often when using Vagrant Share Apache doesn't recognize the ServerName, causing it to return the default application. This can be temporarily resolved by adding the Vagrant Share generated domain as a ServerAlias in your virtual host:

  • Add ServerAlias something-random-1234.vagrantshare.com to your virtual host
  • Restart Apache: sudo service apache2 restart
  • Make sure you don't kill the Vagrant Share signal while doing this. If you do, it'll generate a new domain which will cause this solution to fail.

That's it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment