Build & deploy PHP applications* brief introduction
Who am I ? Anton Babenko @antonbabenko Tech lead at Zoozoo.com Symfony2/PHP/MySQL
Develop > Build > Test > Deploy
Develop > Build > Test > Deploy Develop locally, run some tests, commit and push code…
Develop > Build > Test > Deploy ?
Develop > Build > Test > Deploy Automate
Develop Build Test Deploy Automate and get: ● Faster development cycle ● Easier handover to new team members ● Improves quality ● Reduces errors ● Saves time ● Establish routine process which team can rely on
Develop Build Test Deploy What to automate: ● Dependency & configuration management ○ Using Puppet, Chef, Ansible, bash scripting ● Compilation, minification of your assets ● Running tests ● Creation of documentation and changelogs ● Packaging ● Deployment
Develop Build Test Deploy How to build?
Develop Build Test Deploy How to build? Why do you need a build tool? ● To prepare a project to act in a specific environment Should be no room for misconfiguration ● Staging should have environment similar to production
Develop Build Test Deploy Example flow: ● Get project files from VCS ● Configure ● DB Migration ● Run package managers and builders (npm, bower, grunt) ● Upload ● Cache warmup ● Clear opcache
Develop Build Test Deploy Popular build & deployment tools for PHP projects: ● Bash scripting (Still hit #1) ● Apache Ant ● Phing ● Capistrano ● Fabric ● http://en.wikipedia.org/wiki/List_of_build_automation_software or use PaaS
Develop Build Test Deploy PHP PaaS Providers: PagodaBox AppFog Heroku fortrabbit Engine Yard Cloud Red Hat OpenShift Platform dotCloud http://www.phptherightway.com/#servers_and_deployment AWS Elastic Beanstalk cloudControl Windows Azure Zend Developer Cloud Google App Engine Jelastic
Develop Build Test Deploy ● Bash scripting = be creative as you wish ● Jenkins CI + Apache Ant + jenkins-php.org = great starting point ● Phing = “Apache Ant written in PHP” ● Capistrano ● Fabric
Develop Build Test Deploy ● Bash scripting = be creative as you wish ● Jenkins CI + Apache Ant + jenkins-php.org = great starting point ● Phing = “Apache Ant written in PHP” ● Capistrano = for builds and deployments ● Fabric
Develop Build Test Deploy Capistrano is an open source tool for running scripts on multiple servers. It’s primary use is for easily deploying applications. capifony is a deployment recipes collection that works with both symfony and Symfony2 applications. Source: capifony.org
Develop Build Test Deploy # gem install hipchat newrelic_rpm if exists?(:config_hipchat_token) require 'hipchat/capistrano' set :hipchat_token, "#{config_hipchat_token}" set :hipchat_room_name, "Developers chat" end # Recipe: # github.com/ekino/EkinoNewRelicBundle/blob/master/Resources/recipes/newrelic.rb if exists?(:config_newrelic_license) require 'new_relic/recipes' set :newrelic_license_key, "#{config_newrelic_license}" set :newrelic_appname, "You name it" after "deploy", "newrelic:notice_deployment" end Capifony sugar (1/4):
Develop Build Test Deploy after "symfony:composer:install", "symfony:verify_console" namespace :symfony do task :verify_console do capifony_pretty_print "--> Run app/console to verify if parameters.yml has all required keys and application is runnable" if capture("#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} > /tmp/app_console_output 2>&1 ; echo $?'").to_s.strip != "0" run "cat /tmp/app_console_output && rm -rf /tmp/app_console_output" raise CommandError.new("There was an unrecoverable error.") end capifony_puts_ok end end Capifony sugar (2/4):
Develop Build Test Deploy # Update assets_version # Source: https://github.com/kachkaev/KachkaevAssetsVersionBundle namespace :assets_version do task :increment do capifony_pretty_print "--> Increment assets_version" run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} assets_version:increment --env=#{symfony_env_prod}'" capifony_puts_ok end end Capifony sugar (3/4):
Develop Build Test Deploy # Run migration on one DB server instead of all: role :web, "www1.mysite.com", "www2.mysite.com" role :app, "www1.mysite.com", "www2.mysite.com" role :db, "db1.mysite.com", :primary => true role :db, "db2.mysite.com" role :db, "db3.mysite.com" Capifony sugar (4/4):
Develop Build Test Deploy Capifony questions? http://stackoverflow.com/questions/tagged/capifony Want something with GUI? http://www.deployhq.com/
Develop Build Test Deploy Questions? Questions? Questions? Questions?
Thanks!

Build & deploy PHP application (intro level)

  • 1.
    Build & deploy PHPapplications* brief introduction
  • 2.
    Who am I? Anton Babenko @antonbabenko Tech lead at Zoozoo.com Symfony2/PHP/MySQL
  • 3.
    Develop > Build> Test > Deploy
  • 4.
    Develop > Build> Test > Deploy Develop locally, run some tests, commit and push code…
  • 5.
    Develop > Build> Test > Deploy ?
  • 6.
    Develop > Build> Test > Deploy Automate
  • 7.
    Develop Build TestDeploy Automate and get: ● Faster development cycle ● Easier handover to new team members ● Improves quality ● Reduces errors ● Saves time ● Establish routine process which team can rely on
  • 8.
    Develop Build TestDeploy What to automate: ● Dependency & configuration management ○ Using Puppet, Chef, Ansible, bash scripting ● Compilation, minification of your assets ● Running tests ● Creation of documentation and changelogs ● Packaging ● Deployment
  • 9.
    Develop Build TestDeploy How to build?
  • 10.
    Develop Build TestDeploy How to build? Why do you need a build tool? ● To prepare a project to act in a specific environment Should be no room for misconfiguration ● Staging should have environment similar to production
  • 11.
    Develop Build TestDeploy Example flow: ● Get project files from VCS ● Configure ● DB Migration ● Run package managers and builders (npm, bower, grunt) ● Upload ● Cache warmup ● Clear opcache
  • 12.
    Develop Build TestDeploy Popular build & deployment tools for PHP projects: ● Bash scripting (Still hit #1) ● Apache Ant ● Phing ● Capistrano ● Fabric ● http://en.wikipedia.org/wiki/List_of_build_automation_software or use PaaS
  • 13.
    Develop Build TestDeploy PHP PaaS Providers: PagodaBox AppFog Heroku fortrabbit Engine Yard Cloud Red Hat OpenShift Platform dotCloud http://www.phptherightway.com/#servers_and_deployment AWS Elastic Beanstalk cloudControl Windows Azure Zend Developer Cloud Google App Engine Jelastic
  • 14.
    Develop Build TestDeploy ● Bash scripting = be creative as you wish ● Jenkins CI + Apache Ant + jenkins-php.org = great starting point ● Phing = “Apache Ant written in PHP” ● Capistrano ● Fabric
  • 15.
    Develop Build TestDeploy ● Bash scripting = be creative as you wish ● Jenkins CI + Apache Ant + jenkins-php.org = great starting point ● Phing = “Apache Ant written in PHP” ● Capistrano = for builds and deployments ● Fabric
  • 16.
    Develop Build TestDeploy Capistrano is an open source tool for running scripts on multiple servers. It’s primary use is for easily deploying applications. capifony is a deployment recipes collection that works with both symfony and Symfony2 applications. Source: capifony.org
  • 17.
    Develop Build TestDeploy # gem install hipchat newrelic_rpm if exists?(:config_hipchat_token) require 'hipchat/capistrano' set :hipchat_token, "#{config_hipchat_token}" set :hipchat_room_name, "Developers chat" end # Recipe: # github.com/ekino/EkinoNewRelicBundle/blob/master/Resources/recipes/newrelic.rb if exists?(:config_newrelic_license) require 'new_relic/recipes' set :newrelic_license_key, "#{config_newrelic_license}" set :newrelic_appname, "You name it" after "deploy", "newrelic:notice_deployment" end Capifony sugar (1/4):
  • 18.
    Develop Build TestDeploy after "symfony:composer:install", "symfony:verify_console" namespace :symfony do task :verify_console do capifony_pretty_print "--> Run app/console to verify if parameters.yml has all required keys and application is runnable" if capture("#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} > /tmp/app_console_output 2>&1 ; echo $?'").to_s.strip != "0" run "cat /tmp/app_console_output && rm -rf /tmp/app_console_output" raise CommandError.new("There was an unrecoverable error.") end capifony_puts_ok end end Capifony sugar (2/4):
  • 19.
    Develop Build TestDeploy # Update assets_version # Source: https://github.com/kachkaev/KachkaevAssetsVersionBundle namespace :assets_version do task :increment do capifony_pretty_print "--> Increment assets_version" run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} assets_version:increment --env=#{symfony_env_prod}'" capifony_puts_ok end end Capifony sugar (3/4):
  • 20.
    Develop Build TestDeploy # Run migration on one DB server instead of all: role :web, "www1.mysite.com", "www2.mysite.com" role :app, "www1.mysite.com", "www2.mysite.com" role :db, "db1.mysite.com", :primary => true role :db, "db2.mysite.com" role :db, "db3.mysite.com" Capifony sugar (4/4):
  • 21.
    Develop Build TestDeploy Capifony questions? http://stackoverflow.com/questions/tagged/capifony Want something with GUI? http://www.deployhq.com/
  • 22.
    Develop Build TestDeploy Questions? Questions? Questions? Questions?
  • 23.