Since a few weeks I’ve been using nothing but vm’s to run my web-development projects on. I started, just like everyone else I guess, with installing everything on my local system and running my code from there. I wanted to step away from this approach for quite a few reasons, all of them use cases for Vagrant:
- Wanting to separate project-specific dependencies from each other. If I need a certain component in project A, I don’t want to deal with it’s incompatibility with something else in project B
- Keeping track of dependencies for those projects
- Having an environment that I can easily share with / transfer to other developers
- Being able to develop on exactly the same platform as where the code will be deployed on
- Keeping all that software out of my local system
- I’ve had a rather hard time just setting up my own LAMP and Symfony2 environment. Partially because I didn’t know where to look, partially because there just isn’t that much information about it available yet. Consider this my 2 cents to try and help
Vagrant is a sort of wrapper around Virtualbox. It’s let’s you easily create vm’s, share folders, forward ports, … In short: it makes working with vm’s a lot less of a pain in the *ss.
Discover and install Vagrant here: http://vagrantup.com/
Puppet is used to describe a system’s configuration in plain text. This way your infrastructure becomes versionable and much easier maintainable. When something changes in the system dependencies (for example, if I add a feature that requires APC), I add the apc installation to the Puppet ‘manifest’, which is then shared through the repository like everything else.
To get the most out of it, read the Puppet docs here: http://puppetlabs.com/
Vagrant takes care of the creating/booting the virtual machine, manage virtual ports and shared folders with the host, and other things. But it will depend upon another system to provision the newly created vm. I.e. install packages, configure settings, etc. You can either use Chef or Puppet for this. I went with the latter.
For more information on Vagrant provisioning, check here: http://vagrantup.com/docs/getting-started/provisioning.html
I’ll share my own Vagrantfile, which works for me, I sincerely hope it works for you too :-)
Taking care of the software: Symfony2 modules
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant::Config.run do |config| # Every Vagrant virtual environment requires a box to build off of. config.vm.box = “lucid64” config.vm.box_url = “http://files.vagrantup.com/lucid64.box” # Map a guest port to our own localhost port (I don't really use this) config.vm.forward_port 80, 8002 # Share the /vagrant folder as NFS instead of ‘default’, prevents permission problems config.vm.share_folder(“v-root”, “/vagrant”, “.”, :nfs => true) # Assign host-only IP to this VM, needed for NFS to work # *.1 is assigned to the host config.vm.network :hostonly, “10.1.0.3” # Provision with Puppet config.vm.provision :puppet do |puppet| puppet.manifests_path = “puppet/manifests” puppet.manifest_file = “default.pp” puppet.module_path = “puppet/modules” end end
Before even thinking about Symfony2 requirements, I needed a basic LAMP setup. I found great inspiration at this repo, which deserves full credit: https://github.com/whatsthatweb/vagrant-puppet-LAMP
I needed to adapt a few things (to set, for example, a configurable MySQL password), which I did in my own repo.
I then went through the Symfony2 config.php page to see which dependencies needed fixing. (For example: sqlite, date.timezone settings, etc.)
These requirements have been gathered in my own (and first public) repository here: https://github.com/dietervds/puppet-symfony2How to use it
- In the same folder as your Vagrantfile, create a ‘/puppet’ directory.
- In this directory, put the files from the puppet-symfony2 repository (the manifests and the modules directories)
- In your Vagrantfile, put the following (like in my example a bit back):
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.manifest_file = "default.pp"
puppet.module_path = "puppet/modules"
- Go to the /puppet/manifests/default file, which is the hostfile for the site you’ll bring up, and change it to your needs
- Type ‘vagrant up’
That should be it!
You can add anything you want to the manifests (if you have read the Puppet documentation, it should be rather easy) Also, feel free to tweak things for the better and send me a pull request.
In case I didn’t make this clear yet: it’s my first real Puppet use, and my first GitHub project, so any feedback is more then welcome. Please be gentle ;-)