Skip to content
leibowitz edited this page Mar 17, 2013 · 28 revisions

Requirements

You will need

  • librarian-chef
  • vagrant
  • ssh

Provision

  • PHP >= 5.3
  • MongoDB >= 2.2
  • Python
  • Apache2, Nginx or any webserver
  • RabbitMQ
  • PhantomJS >= 1.5
  • Supervisor

Installation

The easiest way to install is to use chef. This will install all the components for you and supports multiple distributions.

Install ruby, chef and librarian-chef

sudo apt-get install ruby rubygems
sudo gem install chef
sudo gem install librarian

Create Cheffile

site 'http://community.opscode.com/api/v1'

cookbook 'apache2', '>= 1.0.0'
cookbook 'git'
cookbook 'php'
cookbook 'composer'
cookbook 'rabbitmq'
cookbook 'mongodb-10gen'
cookbook 'python'
cookbook 'supervisor',
 :git => 'https://github.com/escapestudios/chef-supervisor'
cookbook 'phantomjs'
cookbook 'nodejs'
cookbook 'npm'

Librarian Chef

Use librarian-chef to download all cookbooks on your machine.

librarian-chef update

You are ready to use these recipes with whatever you choose, for example with Vagrant.

sudo gem install vagrant
vagrant box add precise64 http://files.vagrantup.com/precise64.box
vagrant init precise64

Copy this to a file called Vagrantfile

Vagrant::Config.run do |config|
  # Setup the box
  config.vm.define :perf do |perf_config|
      perf_config.vm.box = "precise64"
      perf_config.vm.forward_port 80, 4567
      perf_config.vm.network :hostonly, "10.0.0.5"
      perf_config.vm.provision :chef_solo do |chef|
      chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
         # chef.roles_path = "roles"
         # chef.data_bags_path = "data_bags"
         chef.add_recipe "php"
         chef.add_recipe "apache2"
         chef.add_recipe "apache2::mod_php5"
         chef.add_recipe "mongodb-10gen"
         chef.add_recipe "mongodb-10gen::single"
         chef.add_recipe "rabbitmq"
         chef.add_recipe "git"
         chef.add_recipe "composer"
         chef.add_recipe "phantomjs"
         chef.add_recipe "nodejs::install_from_package"
         chef.add_recipe "npm"
         chef.add_recipe "python::package"
         chef.add_recipe "supervisor"
         chef.add_recipe "php-mongo"
         chef.add_recipe "python-libs"
         chef.add_recipe "perfmonitor"
      end
  end
end

The last three lines php-mongo, python-libs, and perfmonitor refers to custom recipes. They should be placed in a different directory, like site-cookbooks, as otherwise librarian-chef will delete them when you run librarian-chef install/update.

site-cookbooks/php-mongo/recipes/default.rb

php_pear "mongo" do
    action :install
end 

site-cookbooks/python-libs/recipes/default.rb

python_pip "pika" do
    action :install
end

python_pip "pymongo" do
    action :install
end

site-cookbooks/perfmonitor/recipes/default.rb

git "/var/www/perfmonitor" do
  repository "git://github.com/leibowitz/perfmonitor.git"
  reference "master"
  action :sync
end

execute "updatecomposer" do 
  command "cd /var/www/perfmonitor && sudo composer install"
  action :run
end

execute "installless" do
  command "sudo npm install less -g"
  action :run
end

execute "fixpermissions" do
  command "cd /var/www/perfmonitor/app && sudo chgrp -R www-data cache logs && sudo chmod -R g+rw cache logs"
  action :run
end

execute "asseticdump" do
  command "cd /var/www/perfmonitor && sudo php app/console assetic:dump"
  action :run
end

Now you are ready to create your box with vagrant.

vagrant up perf

Browse the app at http://localhost:4567/perfmonitor/web/app.php

Finally log-in to the machine and start the python process

vagrant ssh
python /var/www/perfmonitor/bin/receive.py &
Clone this wiki locally