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.
- Create a free account at HashiCorp's Atlas.
- Login using
vagrant login
. - SSH into the virtual machine using
vagrant ssh
. - 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. - Inside
/etc/apache2/ports.conf
addListen 81
right underListen 80
. - Restart the server:
sudo service apache2 restart
In the terminal on your host machine enter the following:
vagrant share --http 80
vagrant share --http 81
This will create two links for you looking like http://something-random-1234.vagrantshare.com/.
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!