Announcing Scotch Box 2.0 – Our Dead-Simple Vagrant LAMP Stack Improved

Today we’re proud to announce a major update to our dead-simple Vagrant LAMP stack “Scotch Box”. If you don’t already know, Scotch Box is a preconfigured and pre-provisioned Vagrant box with all your LAMP stack needs built with the intention of being super reliable and easy to use. It’s perfect for PHP apps ranging from simple WordPress projects to complex Laravel projects.

Right now, we’re at almost 200,000 downloads-to-date and growing! We’re hoping to be in the top 10 most most downloaded Vagrant boxes by the end of the year.

With this update, we’re aiming to make Scotch Box easier for the small projects, but also powerful enough for your larger and more advanced PHP projects. It’s faster, more up-to-date, and better than ever before.

The major updates in 2.0 are:

  • Updated the OS to Ubuntu to 14.04 LTS (Trusty Tahr)
  • Updated PHP to PHP 5.6
  • Improved performance through NFS Synced folders in the Vagrantfile starter
  • Updated Ruby to Ruby 2.2.x
  • Added Beanstalked
  • Added PostgreSQL and SQLite
  • Added Redis
  • Easily add multiple domains/site to a single VM (Scotch Box is now Virtual Host ready!)
  • Added a bunch of new demo stuff to get you started faster

Continue reading this article for a full list of improvements.

Get Started

Here’s a list of resources to get you started:

First timers

If it’s your first time using Scotch Box, it’s extremely easy to get setup. First clone the Repo:

git clone my-project

Then cd into that folder:

cd my-project

Then simply run:

vagrant up

For a full list of Vagrant commands from here (like pausing the Vagrant Box), check the easy-to-read the docs.

Already using Scotch Box?

If you’re already using Scotch Box, first let’s delete your known_hosts file. This isn’t required, but you should do this as a preventative action for weird SSH issues:

rm ~/.ssh/known_hosts

Next, update your Vagrantfile by doing a git pull or by cloning a new repo. So:

cd /blah/path/to/scotchbox/cloned/repo
git pull

Or, for new projects:

git clone my-project
cd my-project

Next, update the box with the simple command:

vagrant box update

That’s it! Heads up! If you’re getting weird SSH connection or authentication issues with Scotch Box 2.0, trying adding this to your Vagrantfile for the time being:

config.ssh.username = "vagrant"
config.ssh.password = "vagrant"

There seems to be some weird bug with Vagrant 1.7+ and packaging boxes. Scotch Box will update to fix this when we know what’s happening.

What’s new in Scotch Box 2.0?

We added a ton of updates. Here they are broken into pieces:

System Stuff

  • Updated the OS to Ubuntu to 14.04 LTS (Trusty Tahr)
  • Updated PHP to PHP 5.6
  • Updated Ruby to Ruby 2.2.x
  • Added Vim
  • Added Beanstalkd
  • Added the newest node version
  • Updated Git, cURL, ImageMagick, and Composer

Database Stuff

  • Added PostgreSQL
  • Updated MySQL (We stopped at version 5.5 because 5.6 requires a little too much memory for this box to be worth it. We would have had to dictate a minimum amount of memory to be used with the box.)
  • Added SQLite

Caching Stuff

  • Added Redis
  • Updated Memcached

Node Stuff

  • Updated Grunt
  • Updated Bower
  • Updated Yeoman
  • Updated Gulp
  • Updated Browsersync
  • Added PM2

Laravel Stuff

  • Added Laravel Installer
  • Added Laravel Envoy
  • Added Blackfire Profiler

Misc Stuff

  • Made virtual host ready (see below)
  • Fixed shared folder permission issues with Apache
  • Added “unzip”
  • Enabled PHP short tags
  • Enabled Apache modules to support H5BP’s server configs
  • Added PHP intl extension
  • Setup Vagrantfile to use NFS by default for better performance. Check it out here.
  • Added my.cnf file for quicker mysql command line stuff
  • New documentation

Things Removed

  • Support for Chef and Puppet (see below)
  • Local Bootstrap files in home directory


We cover mostly everything you will ever need in a LAMP stack, but sometimes you’ll want a little more than this provides.

We dropped out-of-the-box support for Chef and Puppet since if you’re using these type of tools, you should probably be provisioning the entire server anyways.

We recommend shell provisioning for adding anything to Scotch Box or manually updating the box via vagrant ssh. Continue reading this post for a a bunch of demos of the most commonly requested additions.

You can add whatever you want to be executed on vagrant up by simply adding this to your Vagrantfile:

config.vm.provision "shell", inline: <<-SHELL
    # Shell commands here...
    echo "Hello, I will be printed on screen during Vagrant Up."

Multiple Domains (Virtual Hosts)

I’m a true believer of having a single virtual machine (or separate Scotch Box) to each project. It’s nice containing an entire project to a single virtual machine.

Some projects require that you setup multiple domains (like a WordPress multisite), some computers are limited by space and size and don’t have the room to host multiple VMs at once, and some people simply like having all their projects tied to a single VM (Homestead is actually excellent for this).

If you know basic web server configurations with Apache, this all should be fairly straight forward. If you know none of that, just copy-and-paste these scripts to get it working.

Let’s create a Scotch Box instance with 3 URLs site1.local, site2.local, site3.local. First update your Vagrantfile like so:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config| = "scotch/box" "private_network", ip: ""
    config.vm.hostname = "scotchbox"
    config.vm.synced_folder ".", "/var/www", :nfs => { :mount_options => ["dmode=777","fmode=666"] }

    config.vm.provision "shell", inline: <<-SHELL

        ## Only thing you probably really care about is right here
        DOMAINS=("site1.local" "site2.local")

        ## Loop through all sites
        for ((i=0; i < ${#DOMAINS[@]}; i++)); do

            ## Current Domain

            echo "Creating directory for $DOMAIN..."
            mkdir -p /var/www/$DOMAIN/public

            echo "Creating vhost config for $DOMAIN..."
            sudo cp /etc/apache2/sites-available/scotchbox.local.conf /etc/apache2/sites-available/$DOMAIN.conf

            echo "Updating vhost config for $DOMAIN..."
            sudo sed -i s,scotchbox.local,$DOMAIN,g /etc/apache2/sites-available/$DOMAIN.conf
            sudo sed -i s,/var/www/public,/var/www/$DOMAIN/public,g /etc/apache2/sites-available/$DOMAIN.conf

            echo "Enabling $DOMAIN. Will probably tell you to restart Apache..."
            sudo a2ensite $DOMAIN.conf

            echo "So let's restart apache..."
            sudo service apache2 restart




Now run:

vagrant up

You should see some outputs now at the end of your vagrant up like so:

Vagrant multiple websites

You’ll also see now two empty folders were created in the Scotch Box directory site1.local/public and site2.local/public. Now you can add whatever you want here for these sites. In order to access them, simply add the following line to your computer’s hosts file (on mac located at /etc/hosts). You can automate this process with Vagrant plugins. site1.local site2.local

Now you should be able to access these public folders by simply visiting the URL in your browser http://site1.local or http://site2.local.

You probably noticed we didn’t add site3. I waited to demo here what it would be like to add a site to an existing project. So, add site3 to the array in the Vagrantfile:

DOMAINS=("site1.local" "site2.local" "site3.local")

Then simply update the box with:

vagrant provision

You’ll notice site3.local/public was created. Now all you need to do is update your hosts file again and you’re all set. This is insanely useful but still dead-simple following the Scotch Box philosophy.

Hopefully you now understand how provisioning works between the Vagrantfile and vagrant up and vagrant provision commands. You can do a ton of things with this and get as crazy as you want. If you’re getting really crazy though, you might want to look into Chef or Puppet instead of Shell provisioning.

Update Packages on Vagrant Up

You can easily update your server’s packages each time you run Vagrant Up if you want to make sure everything stays up to date. Here’s what this would look like.

config.vm.provision "shell", inline: <<-SHELL
    sudo apt-get update
    sudo apt-get upgrade -y

Creating Environment Variables

Sometimes you need to set environment variables (like in Laravel). Here’s a quick example of what a Vagrantfile would look like to create a APP_ENV and DB_PASS variable:

config.vm.provision "shell", inline: <<-SHELL
    sudo bash -c \'echo export APP_ENV="development" >> /etc/apache2/envvars\'
    sudo bash -c \'echo export DB_PASS="meowmeowmeow" >> /etc/apache2/envvars\'

    sudo service apache2 restart

Then, in your PHP, you could just do something like this to get the variable:

echo getenv('APP_ENV');
echo get_env('DB_PASS');

Installing Xdebug

I chose to leave Xdebug out of this box. If you want to add it, you can do something like this:

config.vm.provision "shell", inline: <<-SHELL
    sudo apt-get install php5-xdebug
    sudo service apache2 restart

You also might want to check out this additional resource.

Changing /public to /public_html

Some people prefer to have their root folder to be in public_html instead of public. This is quite easy with the following script:

config.vm.provision "shell", inline: <<-SHELL
    mv /var/www/public /var/www/public_html
    sudo sed -i s,/var/www/public,/var/www/public_html,g /etc/apache2/sites-available/000-default.conf
    sudo sed -i s,/var/www/public,/var/www/public_html,g /etc/apache2/sites-available/scotchbox.local.conf
    sudo service apache2 restart

Import a Database Dump

This is a commonly requested feature. All you need to do is add an SQL file called dump.sql in the Scotch Box folder and add this to your Vagrantfile.

config.vm.provision "shell", inline: <<-SHELL
    mysql -u root -proot scotchbox < /var/www/dump.sql

To reimport, just run: vagrant provision.

Add Composer to PATH

Composer by default isn't in the PATH. You probably want it to be though so you can access things like the Laravel Installer. Add this to your Vagrantfile to get this working:

    config.vm.provision "shell", inline: <<-SHELL

        export PATH="~/.composer/vendor/bin:$PATH" 


Want the older box back?

Maybe Scotch Box 2.0 is buggy or not working for you like older versions did. That's okay - we're working on it. We're still hosting the old boxes, so you can still use them if you want. Just add either of these lines to your Vagrantfile:

config.vm.box_version < 2.0


config.vm.box_version = 1.5


So that's what's new with Scotch Box 2.0! We're going to continue to support it, host the box, and update it. The truth is though, prepackaging all this into a box though is a huge pain. So I wanted to quickly tell you all what's in store for Scotch Box 3.0 whenever we release that (we're looking for help with it too).

The Future of Scotch Box

The next iteration of Scotch Box will probably be a dead-simple install script. We want to make it easy for you guys to be able to switch things up, but still not to worry about provisioning. So down the road, if you want Nginx instead of Apache, no problem. If you want HHVM installed, just a minor config setting.

We'll also be looking to set this up with Packer. By doing this we'll be able to do more. Things like providing support for other Providers such as VMWare, Amazon and more.

Eventually, you'll be able to develop locally with Scotch Box and deploy it with ease. Atlas, by the creators of Vagrant, provide some awesome tools for this and we're going to look into completely the dev experience with Scotch Box and making it as easy as possible.

Finally, this round of Scotch Box has a ton of scripts with it for doing more. If you find yourself constantly pushing the limits with Scotch Box, it might be time to check out some other resources to aid you with local environements: