Provisioning new Virtualbox LAMP development VMs from scratch can be dome with minimal effort using vagrant. By making this process easy and fast I can dedicate an entire VM environment for each development project I have on hand and be sure that my environment remains consistent. That last part is not new, we have been using VMs like this for years but in my experience the VMs often become too valuable because of the manual effort required for initial set up, provisioning software, and ongoing maintenance. Vagrant scripts enable me to build and destroy VMs several times a day at speed, as and when required - removing the manual overhead.
No more "it works on my machine" scenarios, keep development environments isolated and in line with production specifications.
Available here https://github.com/pipe-devnull/vagrant-dev-lamp my basic LAMP Development environment includes:
UPDATE 30/07/2013: New version includes xhprof profiler built in, see PHP Vagrant development instance with xhprof profiler
1. Install Virtualbox
2. Install vagrant
3. Install vagrant base box
# You can use an alternative base box if you wish vagrant box add precise64 http://files.vagrantup.com/precise64.box
# Clone the Vagrant LAMP stack configuration git clone --recursive https://github.com/pipe-devnull/vagrant-dev-lamp.git # enter the cloned directory cd vagrant-dev-lamp # Build the VM using vagrant vagrant up
On my now slightly old dual core machine it takes about 7 minutes to build.
If you want to change the base box you just need to add the box you do want into your environment (like in the command above) and then edit the Vagrantfile, replacing the base box name in the line config.vm.box = "precise64" with the one alternate one just added. You can also build your own base box if you wish, there is also a tool available to help with that https://github.com/jedi4ever/veewee.
Puppet, chef or shell? You can provision the software and services with any, I'm using Puppet, mainly because I have some good modules that make installing Apache, MySQL, PHP and common PHP tools quick and easy, my requirements here are basic and you do not need to know huge amounts about Puppet to get things working.
In order to use the puppet modules for provisioning within vagrant I've included them as git submodules (inside the directory puppet/modules) and added a line into the vagrant file specifying where it should look for to find my puppet modules:
config.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.module_path = "puppet/modules" puppet.manifest_file = "lamp.pp" end
Remote debugging via xdebug is enabled during the VM creation, all you need to do is configure your IDE to use it. Here are some instructions on how to do that using eclipse PDT.
1 Go to Window > Preferences
2 Drill down through PHP > Debug > Installed Debuggers
3 Select XDebug from the right hand side and click 'Configure'
4 Change the setting 'Accept remote session (JIT)' to 'localhost' and click OK
5 In the same settings window drill down through PHP > PHP Servers
6 Click the New button on the right hand side
...6.1 Name the server i.e. 'Remote'
...6.2 Enter the base URL 'http://localhost:8888'
...6.3 Enter the path to the web root, this is the path to the vagrant synced folder '/path/to/vagrant/www'
...6.4 Click 'Finish' and then set the new server as the default (or optionally configure this manually when setting up each debug session)
The above will work with the base LAMP stack, if you have multiple environments in play then you may have to change the port numbers in use appropriately.