Skip to content

Chef cookbook to installs and configures PHP high availability web application with HAProxy, Varnish, Memcached, Percona XtraDB Cluster

Notifications You must be signed in to change notification settings

Cloudxtreme/php-ha-multi-tier-app-cookbook

 
 

Repository files navigation

(Deprecated) This repository was moved to https://github.com/haapp

PHP High Availability Multi Tier Application Chef Cookbook

(This guide is for PHP developers and system administrators without DevOps experience, yet assuming you know how to use Git)

These Cookbooks aims to keep and maintain consistent configuration between development server, stagnig server, and production server with ease and safety of operation and development in mind by installing and configuring following tiers of services:

**PXC is a MySQL Database enhanced with Galera multi-master replication library which enables PHP developer to utilize multiple database without differenciating DB-read code and DB-write code

A common cookbook for all servers enables following operations/features for all Servers easing day to day system administration work:

  • Linux users with ssh key access can be added, modified or removed at once in all VMs
  • Time zone and ntp can be configured at once
  • Monit with automatic restarting when service process dead, send email notification in such event via SMTP (optionally)
  • Newrelic Server Monitoring with custom configuration (optionally)

Pre Reqirements

Enable VT-x in Windows 8, in Windows 7

Install following DevOps tools:

in Windows cmd (Administrator) or ConEmu with Chocolatey:

C:\Users\John>choco install virtualbox -y
C:\Users\John>choco install vagrant -y
C:\Users\John>choco install chefdk -y

in Mac Terminal with Homebrew and Cask:

$ brew cask install virtualbox
$ brew cask install vagrant
$ brew cask install chefdk

in Ubuntu Terminal with apt-get:

$ sudo apt-get install virtualbox
$ sudo apt-get install vagrant
$ sudo apt-get install chefdk

PHP Development Workflow

**fllowing sections, subl command is used to launch Sublime Text as editor from command line to edit files

git clone https://github.com/joelhandwell/php-ha-multi-tier-app-cookbook.git
cd php-ha-multi-tier-app-cookbook
vagrant up

This will trigger Vagrant Chef Zero Provisioner to install HAProxy, Varnish, Apache HTTP, Memcached, PXC in one VM managed by Vagrant. Following Vagrant commands are available to shutdown(poweroff), delete, create/poweron, reconfigure (with chef) the development server:

vagrant halt
vagrant destroy
vagrant up
vagrant provision

make some page in automatically created VM's document root directory syncronized with host machine via Vagrant:

subl websites/examplewebsite.com/index.php

use HostAdmin for Chrome or for FireFox to point examplewebsite.com 192.168.33.10 which is Vagrant's private ip address

Open http://examplewebsite.com in browser to see the index.php is displayed. Change index.php, and refresh browser, developers do not need to use FTP to see changes, but changes are applied immediately in dev server when it's changed in host machine due to sync.

Cookbook Development Workflow

Create feature branch

git checkout -b feature

Write chefspec test, modify cookbook, and run test, repeat till pass

subl spec/w_common/default_spec.rb
subl cookbook/w_common/recipes/default.rb
chef exec rspec spec/w_common/default_spec.rb

if you passed chefspec test, write serverspec test

subl test/integration/test_w_common/serverspec/localhost/default_spec.rb

create and execute initial apply Chef cookbook onto VM

chef exec kitchen list
chef exec kitchen create common
chef exec kitchen setup common

if you get error, modify cookbook and apply Chef again

subl cookbook/w_common/recipes/default.rb
chef exec kitchen converge common

run serverspec

if it's executed without error, run serverspec test, and if test fail, edit cookbook until pass, and delete VM after pass, and run end to end test for make sure, and commit change.

subl cookbook/w_common/recipes/default.rb
chef exec kitchen converge common

subl cookbook/w_common/recipes/default.rb
chef exec kitchen converge common

chef exec kitchen destroy common
chef exec kitchen test common

git add cookbook/w_common/recipes/default.rb
git commit

About

Chef cookbook to installs and configures PHP high availability web application with HAProxy, Varnish, Memcached, Percona XtraDB Cluster

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 99.8%
  • Other 0.2%