To setup staging you require.
- Virtual Box
Vagrant allows you to spin up as many Linux virtual boxes as you want, whenever you need them. It isolates dependencies and their configuration in a single file called “Vagrantfile”. So instead of installing your dependencies one at a time you can just create a Vagrantfile and Vagrant handles the rest of the setup.
Seting up vagrant
Note: make sure that you have 1-2 GB of free RAM as Vagrant runs a full OS in the virtual machine on your system.
- Install Virtual Box in your machine.
- Install Vagrant in your machine.
- Pick the box that you want to spin up at vagrantcloud.com
vagrant box add “name_of_the_box”.
- Go to the project folder.
So just like that you have a virtual Linux box running on your machine.
Configuring The Vagrantfile
This file is the heart and soul of your vagrant setup and you can use it to normalise and automate the process of setting up your virtual machine. A lot of stuff like provisioning, networking and syncing application folder can be automated directly from this file.
Setting Up The Networking:
config.vm.network "private_network", ip: "192.168.33.10"
This creates a private network. You also get options for port forwarding or connecting to public network.
Setting The Synced folders:
It enables Vagrant to sync folders on the host machine to the virtual machine.
config.vm.synced_folder "./", "/home/vagrant/app"
The first parameter is a path to a directory on the host machine. If the path is relative, it is relative to the project root. The second parameter must be an absolute path of where to share the folder within the virtual machine.
Provisioning The Virtual Machine:
Provisioner in Vagrant allows you to automatically install software, alter configurations, and more on the machines as part of the vagrant up process instead of using ssh and installing all software manually, each time.
config.vm.provision "shell", privileged: false, inline: <<-SHELL
The script will be run in the shell of your virtual machine when you execute
Prashant is an engineer at C42 Engineering. If you liked this post, please consider...
- following @TheData_Ninja on twitter
- subscribing to this blog