(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:
- Loadbalancer: HAProxy 1.5 in 2 VMs with Keepalived
- Web Cache Server: Varnish 4.0 * X with optional GeoIP vmod for loading maxminddb (geoip2) and Header vmod for multiple set-cookie headers
- Web Server: Apache HTTP 2.4 in N number of VMs with PHP 5.5, PHP FPM, in-VM-HAProxy for DB loadbalancing, optional Blackfire Profiler, Newrelic PHP Application Monitoring, Xdebug, phpMyAdmin for PHP Developer's ease of development
- DB Cache Server: Memcached in N number of VMs
- DB Server: Percona XtraDB Cluster(PXC) in N number of VMs
**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)
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
**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.
git checkout -b feature
subl spec/w_common/default_spec.rb
subl cookbook/w_common/recipes/default.rb
chef exec rspec spec/w_common/default_spec.rb
subl test/integration/test_w_common/serverspec/localhost/default_spec.rb
chef exec kitchen list
chef exec kitchen create common
chef exec kitchen setup common
subl cookbook/w_common/recipes/default.rb
chef exec kitchen converge common
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