Quantcast
Viewing all articles
Browse latest Browse all 4

Learn Laravel. Vagrant.

Vagrant is a tool that let’s you easily spin up pre-configured development virtual machines. There are many reasons to use Vagrant but for the purpose of this course let’s just say that it is the recommended Laravel way. There is an official Vagrant box made specifically for Laravel development called Homestead. It integrates extremely well into the workflow and it has no lasting impact on your computer.

notice
These instructions are specific to OS X Yosemite however these concepts can be applied to other operating systems like Windows or Linux.

Vagrant depends on VirtualBox so we will install that first. Go to virtualbox.org and download a binary for your system. Once VirtualBox is downloaded go ahead and install it. Installation is very straight forward and does not require any special instructions.

Now its time to install Vagrant. Go to vagrantup.com and download version for your system. Vagrant installation is just as simple so you should be able to handle it yourself.

That’s it. Let’s try to spin up a box. Go to vagrantcloud.com and find a box that you want to use. For this example lets just use ubuntu/trusty64. Open up terminal and type this in:

vagrant init ubuntu/trusty64

Vagrant will create a file in the current directory called Vagrantfile. This file controls a lot of aspects of the box like networking and shared folders with the host system. We don’t really need to configure it in anyway for our purpose. Start the box with this command:

vagrant up

At this point Vagrant will download the base box we initialized so the first time you try this it will take a while. All subsequent requests will be quick.

You will need to authenticate to Vagrant box using SSH key. If you have ever used them before you might already have a set generated on your computer. Don’t worry if you don’t. Simply run this command:

ssh-keygen

You will be asked few questions but for Vagrant use you can simply hit enter few times to accept the defaults. If you plan to use this key for real world authentication it is a good idea to choose a passphrase.

Our Vagrant box is running and we can SSH into it with this command:

vagrant ssh

You will not be prompted for any passwords since Vagrant uses ssh keys for authentication.  In order to disconnect from the Vagrant SSH sessions simply type in:

exit

In order to shut down the box type in:

vagrant halt

Vagrant has created hidden directory in our current directory that stores any changes you have made to the box. Since we will not be using this box for anything we can clean it up with this command:

vagrant destroy

This removes the state of the machine. I am not a big fan of this command since it leaves a residual hidden directory:

.vagrant

Instead of running vagrant destroy I like to just remove that directory:

rm -R .vagrant

And if you don’t need this box ever again you can also delete the Vagrantfile:

rm Vagrantfile

One thing to remember is that you have cleaned up your instance of the box but the base image remains on your machine. To see the list of base boxes stored on your computer run this command:

vagrant box list

In order to remove the ubuntu box you can type in this:

vagrant box remove ubuntu/trusty64

While working with Laravel we will not use Vagrant as described above. Laravel provides a custom management tool for Homestead. I just wanted to give you an insight into how Vagrant works and what is actually happening behind the scenes.

I hope you enjoyed this lesson. Check out the Table of Contents post for more.

The post Learn Laravel. Vagrant. appeared first on MattStypa.com.


Viewing all articles
Browse latest Browse all 4

Trending Articles