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

Requirements

You will need

  • librarian-chef
  • vagrant
  • ssh

Provision

  • PHP >= 5.3
  • MongoDB >= 2.2
  • Python
  • Apache2
  • RabbitMQ
  • PhantomJS >= 1.5
  • Supervisor

Installation

The easiest way to install is to use chef. This will install all the components for you (works only with ubuntu at the moment, but feel free to adapt this to your favourite distribution)

Install ruby, chef and librarian-chef

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

Create a Cheffile

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

cookbook 'git', '>= 2.0.0'
cookbook 'rvm',
   :git => 'https://github.com/fnichol/chef-rvm'
cookbook 'rabbitmq'
cookbook 'mongodb-10gen' 
cookbook 'apache2', '>= 1.0.0'
cookbook 'php', '>= 1.1'
cookbook 'python', '>= 1.2.2'
cookbook 'supervisor', 
    :git => 'https://github.com/escapestudios/chef-supervisor'
cookbook 'phantomjs', '>= 0.0.10'
cookbook 'composer'
cookbook 'symfony2',
    :git => 'git://github.com/geoffreytran/chef-symfony2.git'
cookbook 'nodejs'
cookbook 'npm'
cookbook 'lesscss',
    :git => 'git://github.com/geoffreytran/chef-lesscss.git'

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 raring-64 http://cloud-images.ubuntu.com/raring/current/raring-server-cloudimg-vagrant-amd64-disk1.box
vagrant init raring-64

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 = "raring-64"
      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 "mongodb-10gen::single"
         chef.add_recipe "apache2"
         chef.add_recipe "apache2::mod_php5"
         chef.add_recipe "rabbitmq"
         chef.add_recipe "git"
         chef.add_recipe "phantomjs"
         chef.add_recipe "nodejs::install_from_package"
         chef.add_recipe "python::package"
         chef.add_recipe "php::package"
         chef.add_recipe "composer"
         chef.add_recipe "perfmonitor"
         chef.add_recipe "supervisor"
         chef.add_recipe "supervisor::programs"
      end
  end
end

The line perfmonitor refers to a custom recipe. Place it in a different directory, like site-cookbooks, as otherwise librarian-chef will delete it when you run librarian-chef install/update.

site-cookbooks/perfmonitor/recipes/default.rb

execute "installphpmongo" do
  command "sudo pecl install -f mongo"
  action :run
end

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

node[:symfony2][:user] = 'root'

symfony2_console "Generate assets" do
  action :cmd

  command "assetic:dump"

  path '/var/www/perfmonitor'
end

node['supervisor']['programs'] = {
    'queue'=> {
        'name' => 'queue',
        'command' => 'python /var/www/perfmonitor/bin/receive.py',
        'autostart' => true,
        'autorestart' => true,
        'user' => 'vagrant',
        'startsecs' => 2,
        'numprocs' => 1,
    } 
}

package "python-pip" do
    action :install
end

execute "installpythonlibs" do
  command "sudo pip install pymongo pika"
  action :run
end

execute "installphpmongo" do
  command "sudo echo 'extension=mongo.so' >> /etc/php5/apache2/php.ini"
  action :run
end

execute "restartapache" do 
  command "sudo service apache2 restart"
  action :run
end

Now you are ready to create your box with vagrant.

vagrant up

When it's done, browse the app at http://localhost:4567/perfmonitor/web/app.php

Clone this wiki locally