germanny
3/27/2014 - 1:44 PM

Using Vagrant to run local environments from a single VM

Using Vagrant to run local environments from a single VM

Set up a new local environment on a single VM

This creates a new named-based vhost on the IP http://192.168.33.21/.

Installed from https://gist.github.com/JeffreyWay/af0ee7311abfde3e3b73.

See also https://laracasts.com/lessons/get-off-mamp-now.

On my set up, the /vagrant is shared with ~/Sites/projects/. cd to this directory and vagrant up.

Some helpful command line commands:
rm -rf 'foo.txt
!! will repeat last command

to make a new environment on this VM

First, make a new directory with index file:
mkdir Foo
vi index.php

Next, vagrant ssh. Set up the readable url for this project and any other settings.
cd /etc/apache2/sites-available
sudo cp 000-default.conf name-of-new-one.conf (best to keep the name the same everywhere)
sudo vi name-of-new-one.conf
Set DocumentRoot to /var/www/name-of-new-one
Uncomment and set ServerName to name-of-new-one.local
Exit that and then sudo a2ensite name-of-new-one (name of the directory) and sudo service apache2 reload
exit or Ctrl D

Give url a readable name

Open up hosts file sudo vi /etc/hosts
192.168.33.21 name-of-new-one.local
Flush DNS cache: dscacheutil -flushcache; sudo killall -HUP mDNSResponder see http://shaun.net/2012/04/clearing-the-local-dns-cache-on-os-x-lion/
wait a long time - takes about 10-15 min for my machine to clear the DNS