Virtualization
A crash course
Why Do things virtually?
- Allows for you and a team developing on any platform you wish
- Develop against a server that will be the same as your production web server
- Use whatever tools you feel most comfortable with
What tools will we be using?
What role does Vagrant play?
Vagrant is essentially a wrapper around
oracle's virtual box. It provides a nice set
of command line programs that allow you
to do various things with a virtual box, like
starting, stopping, suspending, etc...
It's the glue that makes the magic happen.
What role does Virtualbox play?
Virtualbox is virtualization software that
allows you to run a computer inside your
computer. That virtual machine (or box)
has all the same properties of a normal
computer. It gets an ip address, needs
dedicated resources (that your computer - the host) provides. The operating system
is arbitrary, but windows and linux play
well with virtualbox.
What role does Ubuntu play?
In a typical scenario, the web server that you deploy your websites and applications to will be some flavor of linux. CentOS, Redhat (RHEL), and ubuntu have all become popular options for web servers.
With that in mind, we'll run ubuntu inside of Virtual box, and our web server will live in there. This means no more reliance on wamp, mamp, xampp, etc....
So to recap...
We'll use
to control
which will be
running some flavor of
which will allow us to
install things like
So lets install stuff...
Vagrant
http://www.vagrantup.com
Virtual Box
https://www.virtualbox.org/wiki/Downloads
Putty (windows users)
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Windows Guide:
http://www.sitepoint.com/getting-started-vagrant-windows/
Now that we have everything installed, lets get a box up and running...
vagrant init ubuntu/trusty64
This command will initialize a new Vagrantfile. Open the newly created Vagrantfile in a text editor of your choice
vagrant up
This command will "spin up" a new box. If your pc does not support virtualization, we'll find out now.
ssh, learn to love it
vagrant ssh
This command will login you into the vagrant box via ssh. Windows users may have trouble with this step, that's where PuTTY comes in.
vagrant ssh-config
This command should output the configuration details for ssh so you can ssh into the box via putty.
other vagrant commands
vagrant suspend
This command will essentially take a snapshot of the machine, and close it down. Restarting the machine with vagrant up will not provision the box (more on this later)
vagrant provision
This command will run any provisioning scripts defined in the Vagrantfile.
vagrant destroy
Completely destroys a box, all state is lost. Doing a vagrant up on this machine will need a reprovision.
Do this now
This is not really useful...yet
In order to make this useful, we have to install stuff on the vagrant box (like web servery things, php, mysql, apache, etc...)
git clone git@github.com:ggoforth/bbu
Lets take a look at the new Vagrantfile
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provision "shell", path: "./scripts/provision.sh"
Magic happens here
Running vagrant up from the root of the bbu project will vagrant up the box, and then provision it for use
This will take a while...
Once it's done, point your browser to:
http://localhost:8080
Further reading
Vagrant Docs:
https://docs.vagrantup.com/v2
Linux Shell:
http://linuxcommand.org/learning_the_shell.php
Virtualization
By Greg Goforth
Virtualization
- 456