We use Vagrant as command-line virtualbox wrapper. Mainly to test EasyEngine builds which require fresh OS.
Create a folder for your work environment and change into it.
mkdir vagrant-work && cd vagrant-work
Create a Ubuntu 14.04 LTS 64-bit box
vagrant init ubuntu/trusty64
Above command quickly initializes a vagrantfile in your vagrant-work folder.
Next, we need to start (boot) it by running command:
Above command may take longer for first time as entire OS image gets downloaded behind the scene!
Next, log into the box via SSH!
Forwarding Port 80 from Mac
First, we need to configure vagrantfile to redirect traffic from 8080 to 80 inside localhost:
config.vm.forward_port 80, 8080
Mac OS – till Maverick
If you wish to dedicate port 80 to web-server running inside vagrant i.e. in virtual machine, please run follow command on Mac OS terminal:
sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to me 80
Above will forward any traffic on host machine’s port 80 to port localhost’s 8080.
You can make this permanent as well by following instructions from Douglas Muth.
Mac OS – Yosemite onwards
Install a vagrant plugin
vagrant plugin install vagrant-triggers
Add following to vagrant config file before end
config.trigger.after [:provision, :up, :reload] do system('echo " rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080 " | sudo pfctl -ef - > /dev/null 2>&1; echo "==> Fowarding Ports: 80 -> 8080 & Enabling pf"') end config.trigger.after [:halt, :destroy] do system("sudo pfctl -df /etc/pf.conf > /dev/null 2>&1; echo '==> Removing Port Forwarding & Disabling pf'") end
Above vagrant config is taken from here.