Lucerna – a Vagrant LAMP Stack
For a while now, I’ve been building Vagrant VMs the old fashioned way which has basically involved grabbing a Linux box from the good folks at Vagrant, sshing in, then running a handful of commands and tweaking a couple of config files.
I work with straightforward LAMP and LEMP stacks, so I used to think this wasn’t a problem. I was wrong. It seems that every time a new version of Vagrant or VirtualBox is released I’m left with a box that’s complaining about an outdated set of Guest Additions or some other VM related ailment.
Now, I’m not a dev ops guy, but I do love simple, performant dev environments. What follows is a tutorial for provisioning a LAMP stack on a Vagrant box using Chef Solo. It assumes that you have the latest versions of Vagrant and VirtualBox installed. You should also fork the Lucerna repo so that any customizations you make can be committed to your own repo.
I’m aware that there a lot of these tutorials out there. I don’t claim this is better than any other. What it does attempt to do is hop through all the hoops leading up to actually running vagrant up.
# I'm a Mac user, so let's install Homebrew # If you're using another OS, you'll need to # look into how best to install rbenv, etc. (see below). $ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" # Install rbenv and plugins $ brew install rbenv ruby-build rbenv-gem-rehash # Add rbenv init to your shell to enable shims and autocompletion. $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile # Reload your bash profile $ source ~/.bash_profile # List all available Ruby versions rbenv versions # Install and set Ruby version (2.1.0 is stable at time of writing) $ rbenv install 2.1.0 $ rbenv rehash $ rbenv shell 2.1.0 $ rbenv global 2.1.0 $ rbenv rehash # Check to see if we're using the correct version $ rbenv version # Update Gems $ gem update --system $ gem update # Install berkshelf $ gem install berkshelf # Install vagrant-hostmaster plugin $ vagrant plugin install vagrant-hostmanager # Install vagrant-berkshelf plugin $ vagrant plugin install vagrant-berkshelf # Create a directory for the Lucerna repo # This example creates a directory named 'lucerna' in your home directory $ mkdir ~/lucerna $ cd lucerna # Clone the repo to your local machine git clone email@example.com/jp1971/lucerna.git
You’re now ready to run vagrant up. Before doing so, you may want to change all instances of ‘lucerna’ in the Vagrantfile to something more meaningful to you or your project. You may also want to use something else for server_root_password, server_repl_password, and server_debian_password. I use ‘lucerna’ for everything in the repo for simplicity’s sake.
At some point, you’ll be presented with a ‘password:’ prompt. This is the password of your local machine. It’s required so that Vagrant Host Manager can write to /etc/hosts. Once vagrant up has done its business, you be able to navigate to http://lucerna.local (or whatever you changed it to in the Vagrantfile) and see an ‘It Works!’ page.
Keep in mind that you only need to run the commands above (with the exception of git clone… and vagrant up) once. Get in touch if you have any questions or ideas, find any bugs, etc.