• The Laravel Setup with Vagrant and VirtualBox

    Posted on October 22, 2013 by Kyle in the Other Stuff, Uncategorized.

    Started from the bottom, now we’re here

    I am looking at helping out on a new project that is based on the Laravel framework. I am excited to be able to dive into a Laravel project as I have heard how “elegant” it makes PHP development. I have a new rMBP and wanted a better to contain dev environments. In the past I have used MAMP and MAMP Pro, which both help put the files and tools in place, but I have always worried they are a bit “heavy touch”. Most of the Laravel guys pointed me to Vagrant and Virtual box as a solution. After a bit of research I decided to give it a shot. Here is a brief synaposis of where I landed and what I ended up doing.

    Tech being used:

    Vagrant – This is what makes the magic happen. Vagrant is a tool that allows you to do many things, the important things to me were, scripting a virtual machine (VM) setup, port forwarding and giving me an easy SSH tunnel into a VM.

    VirtualBox – This is the VM software choice by most. This is free, light weight and allows for easy On/Off operation from terminal. No GUI to control really, so we have to rely on “base” images from the web. Which IMO, is not a bad thing.

    Laravel – The framework I wanted to get up on the rails and start getting familiar with.

    Putting it together

    So here is how this all comes together, we are going to use Vagrant to script the setup/install of our virtual box. Once the Vagrant files are created, we pass around this VM with minimal effort – thereby ensuring a similar dev environment.

    First, I want to point out that I was able to find a terrific guide here that walks through the install process. A few notes before you jump over there though,  download the latest version of Vagrant, but download a 4.2 version of Virtual Box. Next, follow the install script in the guide linked above or you can download the git repo I have setup with Laravel 4 already setup in it.

    I am going to assume most folks will want to download the git repo, which if you do, it should have everything you need to turn on the Vagrant box, and start to work in a Laravel 4 framework project. Do still take a peek at the guide as it explains how to turn on the Vagrant box and also SSH into the Vagrant Box. This Vagrant box uses port forwarding on 1337 and can be configured in the VagrantFile at any time. I have disabled the boot up script as everything we need is already installed.


    If you skipped the review of the guide, not a problem. Here are some quick steps on getting into the Vagrant Box:

    1. Install Vagrant
    2. Install Virtual Box 4.2.x
    3. Download the Git repo to a code folder on your machine (I have mine in the documents folder under a code folder, but anywhere should work)
    4. Open terminal and change directory to the location the vagrant file is (for example cd /Users/xxuser/Documents/Git/Laravel4)
    5. Run:  Vagrant up
    6. Run:  Vagrant ssh
    7. If you are on a Mac, you will want to also do a ch mod 777 on the storage folder  (under apps\storage in the repo) – This is on your host, so that the Vagrant box can write changes – http://cl.ly/image/0R310o2H0D2G
    8. Open a browser and navigate to http://localhost:1337

    Let me know if you run into problems in the comments section.

    Post Tagged with , , , , ,

3 Responsesso far.

  1. dcrystalj says:

    So you have put in laravel. It’s not good i think, now we have laravel 4.1 and your vagrant is useless for me

  2. Charles says:

    Thank you very much for this post. I had had a few problems trying to get everything to work, without success, until I stumbled upon your post. Cheers.

Leave a Reply

Your email address will not be published. Required fields are marked *