Rock Solid Deployment     of PHP Applications    Pablo Godel @pgodel - www.pfcongres.com           Sep 15th 2012 - Utrecht...
Who Am I?    ⁃ Born in Argentina, living in the US since 1999    ⁃ PHP & Symfony developer    ⁃ Founder of the original PH...
Saturday, September 15, 2012
Saturday, September 15, 2012
ServerGrove!      ⁃ Founded ServerGrove Networks in 2005      ⁃ Provider of web hosting specialized in PHP,        Symfony...
Community is our teacher            ⁃ Very active open source supporter through code              contributions and usergr...
Deployment                                 ?Saturday, September 15, 2012
Deployment                Software deployment is all of the activities that make                a software system availabl...
Deployment                          A very important part of                          the application life-cycleSaturday, ...
Deployment                A very important critical part                of the application life-cycleSaturday, September 1...
Deployment                               It should not be an                                   after thoughtSaturday, Sept...
Deployment                          It should be predictableSaturday, September 15, 2012
Deployment                               The more you do it the                                   better it goesSaturday, ...
Saturday, September 15, 2012
Deployment: GoalsSaturday, September 15, 2012
Deployment: Goals                 One-click deploysSaturday, September 15, 2012
Deployment: Goals                 One-click deploys              Continuous deploysSaturday, September 15, 2012
PHP Apps                               DeploymentSaturday, September 15, 2012
PHP Apps                               DeploymentSaturday, September 15, 2012
PHP Apps                               DeploymentSaturday, September 15, 2012
Deployment: Goals                                         Anytime & AnywhereSaturday, September 15, 2012
Deployment: Goals                  AnyoneSaturday, September 15, 2012
Deployment: Goals                                              ReliableSaturday, September 15, 2012
Deployment: Goals                RollbacksSaturday, September 15, 2012
Deployment: Goals                                             No downtimeSaturday, September 15, 2012
Deployment: Goals                     ReusableSaturday, September 15, 2012
Deployment: Goals                                              ScalableSaturday, September 15, 2012
Deployment: Goals                          • One-click / continuous deploys                          • Anytime & Anywhere ...
Deployment FactsSaturday, September 15, 2012
Deployment: Fact #1                      Deployment starts with the developer      • Setup development environment to be a...
Deployment: Fact #2                           Success linked to server OS setup      • Use Puppet/Chef to manage OS packag...
Deployment: Fact #3                                  Monitoring is uptime      • Use monitoring tools to know what is goin...
Deployment MethodologiesSaturday, September 15, 2012
Deployment Methodologies                    • VIM-style                    • FTP uploads                    • rsync       ...
Web Apps Deployment:                        Steps overviewSaturday, September 15, 2012
Web Apps Deployment:                          First time                       • Copy files to server(s)                   ...
Web Apps Deployment:                       Subsequent times                         • Copy files to server(s)              ...
Deployment: ChallengesSaturday, September 15, 2012
Deployment: Challenges      Challenge:      Fast & reliable copy of files      Solutions:      • rsync      • git pull     ...
Deployment: Challenges      Challenge:      Scalable      Solutions:      • use a tool that allows to go from 1 to n serve...
Deployment: Challenges      Challenge:      Rollbacks      Solutions:      • test!      • tag releases      • dedicated br...
Deployment: Challenges      Challenge:      Secure      Solutions:      • use ssh based connections      • donʼt store pas...
Deployment: Challenges      Challenge:      DB migrations      Solutions:      • Doctrine Migrations      • Consider docum...
Deployment: Challenges      Challenge:      Static assets       Solutions:       • YUICompress shrinks JS and CSS file size...
Deployment: Challenges      Challenge:      Caching       Solutions:      • Update one server while others handle load    ...
Deployment: Challenges      Challenge:      File permission conflicts       Solutions:       • Run Apache/PHP with same use...
PHP Apps Deployment:                     Other common pitfallsSaturday, September 15, 2012
PHP Apps Deployment:                     Other common pitfalls        • Case sensitive filesystems        • Configuration di...
PHP Apps Deployment:                           ExamplesSaturday, September 15, 2012
PHP Apps Deployment:                           Examples                    Simplest continuous deployment ever!    hook.ph...
PHP Apps Deployment:                           Examples                                          Capistrano               ...
PHP Apps Deployment:                           Examples                               Capistrano    set :application, "mya...
PHP Apps Deployment:                           Examples                                         Capistrano                ...
PHP Apps Deployment:                           Examples                               Capifony (Symfony2)                 ...
PHP Apps Deployment:                           Examples                                    Capifony (Symfony2)            ...
PHP Apps Deployment:                           Examples                               Capifony (Symfony2)    set :keep_rel...
PHP Apps Deployment:                           Examples                                    Capifony (Symfony2)            ...
PHP Apps Deployment:                           Examples                                     Capifony (Symfony2)           ...
PHP Apps Deployment:                           Examples                                    Capifony (Symfony2)            ...
PHP Apps Deployment:                         Other options                      • Fabric                      • WePloy    ...
PHP Apps Deployment:                            ToolsSaturday, September 15, 2012
PHP Apps Deployment:                            Tools                               App Metrics: StatsD & GraphiteSaturday...
PHP Apps Deployment:                            Tools                               Logging: Logstash                Ship ...
PHP Apps Deployment:                            Tools                                 Logging: Logstash Configure Apache to...
PHP Apps Deployment:                            Tools                               Logging: GraylogSaturday, September 15...
PHP Apps Deployment:                            Tools                               Logging: Kibana  Kibana is a user frie...
PHP Apps Deployment:                            Tools                                       Packaging: fpm             Bui...
PHP Apps Deployment:                        Time for demoSaturday, September 15, 2012
PHP Apps Deployment:                           SummarySaturday, September 15, 2012
•Stop using FTPSaturday, September 15, 2012
•Stop using FTP                               •Plan earlySaturday, September 15, 2012
•Stop using FTP                               •Plan early                               •PracticeSaturday, September 15, 2...
•Stop using FTP                               •Plan early                               •Practice                         ...
•Stop using FTP                               •Plan early                               •Practice                         ...
Thank you!                               QUESTIONS?                Rate Me Please! https://joind.in/7079                  ...
Upcoming SlideShare
Loading in …5
×

PFCongres 2012 - Rock Solid Deployment of PHP Apps

8,759 views
8,646 views

Published on

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,759
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
42
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

PFCongres 2012 - Rock Solid Deployment of PHP Apps

  1. 1. Rock Solid Deployment of PHP Applications Pablo Godel @pgodel - www.pfcongres.com Sep 15th 2012 - Utrecht, NL https://joind.in/7079Saturday, September 15, 2012
  2. 2. Who Am I? ⁃ Born in Argentina, living in the US since 1999 ⁃ PHP & Symfony developer ⁃ Founder of the original PHP mailing list in spanish ⁃ Master of the parrillaSaturday, September 15, 2012
  3. 3. Saturday, September 15, 2012
  4. 4. Saturday, September 15, 2012
  5. 5. ServerGrove! ⁃ Founded ServerGrove Networks in 2005 ⁃ Provider of web hosting specialized in PHP, Symfony, ZendFramework, MongoDB and others ⁃ Servers in USA and Europe!Saturday, September 15, 2012
  6. 6. Community is our teacher ⁃ Very active open source supporter through code contributions and usergroups/conference sponsoringSaturday, September 15, 2012
  7. 7. Deployment ?Saturday, September 15, 2012
  8. 8. Deployment Software deployment is all of the activities that make a software system available for use. http://en.wikipedia.org/wiki/Software_deploymentSaturday, September 15, 2012
  9. 9. Deployment A very important part of the application life-cycleSaturday, September 15, 2012
  10. 10. Deployment A very important critical part of the application life-cycleSaturday, September 15, 2012
  11. 11. Deployment It should not be an after thoughtSaturday, September 15, 2012
  12. 12. Deployment It should be predictableSaturday, September 15, 2012
  13. 13. Deployment The more you do it the better it goesSaturday, September 15, 2012
  14. 14. Saturday, September 15, 2012
  15. 15. Deployment: GoalsSaturday, September 15, 2012
  16. 16. Deployment: Goals One-click deploysSaturday, September 15, 2012
  17. 17. Deployment: Goals One-click deploys Continuous deploysSaturday, September 15, 2012
  18. 18. PHP Apps DeploymentSaturday, September 15, 2012
  19. 19. PHP Apps DeploymentSaturday, September 15, 2012
  20. 20. PHP Apps DeploymentSaturday, September 15, 2012
  21. 21. Deployment: Goals Anytime & AnywhereSaturday, September 15, 2012
  22. 22. Deployment: Goals AnyoneSaturday, September 15, 2012
  23. 23. Deployment: Goals ReliableSaturday, September 15, 2012
  24. 24. Deployment: Goals RollbacksSaturday, September 15, 2012
  25. 25. Deployment: Goals No downtimeSaturday, September 15, 2012
  26. 26. Deployment: Goals ReusableSaturday, September 15, 2012
  27. 27. Deployment: Goals ScalableSaturday, September 15, 2012
  28. 28. Deployment: Goals • One-click / continuous deploys • Anytime & Anywhere • Anyone • No downtime • Predictable & Reliable • Rollbacks • Reusable • ScalableSaturday, September 15, 2012
  29. 29. Deployment FactsSaturday, September 15, 2012
  30. 30. Deployment: Fact #1 Deployment starts with the developer • Setup development environment to be as close as possible to productions servers • Setup test/qa/staging servers • Use Vagrant to manage VMs • Use Puppet/Chef to manage OS packages/ configurationSaturday, September 15, 2012
  31. 31. Deployment: Fact #2 Success linked to server OS setup • Use Puppet/Chef to manage OS packages/ configuration • Create OS packages for 3rd party software • Setup your own package repositoriesSaturday, September 15, 2012
  32. 32. Deployment: Fact #3 Monitoring is uptime • Use monitoring tools to know what is going on with your servers (Ganglia, Cacti, Zabbix, etc.) • Add monitoring and metrics to your app (Graphite, StatsD, New Relic) • Use your logs wisely (Graylog, Logstash, Kibana)Saturday, September 15, 2012
  33. 33. Deployment MethodologiesSaturday, September 15, 2012
  34. 34. Deployment Methodologies • VIM-style • FTP uploads • rsync • source control (svn, git) • Build tools (ant, phing) • Specialized tools (capistrano, fabric, etc) • Package based (rpm, deb, etc)Saturday, September 15, 2012
  35. 35. Web Apps Deployment: Steps overviewSaturday, September 15, 2012
  36. 36. Web Apps Deployment: First time • Copy files to server(s) • Set server-side configurations • Load DB fixtures • Process and install assets • Warm up cache • “Enable” siteSaturday, September 15, 2012
  37. 37. Web Apps Deployment: Subsequent times • Copy files to server(s) • Apply DB updates (migrations) • Process and install assets • Warm up cache • “Enable” siteSaturday, September 15, 2012
  38. 38. Deployment: ChallengesSaturday, September 15, 2012
  39. 39. Deployment: Challenges Challenge: Fast & reliable copy of files Solutions: • rsync • git pull • setup git repo on local network to save bandwidth and avoid issues if git server is down (i.e. github)Saturday, September 15, 2012
  40. 40. Deployment: Challenges Challenge: Scalable Solutions: • use a tool that allows to go from 1 to n servers easily (i.e. capistrano) • pssh allows to send commands to n servers in parallel • package your app in OS packages like .rpm/.deb to easily install across n serversSaturday, September 15, 2012
  41. 41. Deployment: Challenges Challenge: Rollbacks Solutions: • test! • tag releases • dedicated branches (master for production) • deploy each release in its own directorySaturday, September 15, 2012
  42. 42. Deployment: Challenges Challenge: Secure Solutions: • use ssh based connections • donʼt store passwords on source control • store sensitive strings (passwords) in server environment variablesSaturday, September 15, 2012
  43. 43. Deployment: Challenges Challenge: DB migrations Solutions: • Doctrine Migrations • Consider document oriented DBs like MongoDB “The best migrations are the ones you don’t have to do”Saturday, September 15, 2012
  44. 44. Deployment: Challenges Challenge: Static assets Solutions: • YUICompress shrinks JS and CSS file sizes • Enable web server compression • Add versioning to static assets links (code.js?v=1) • Assetic combines multiple files into one • Run utilities locally or in a staging server, deploy resultSaturday, September 15, 2012
  45. 45. Deployment: Challenges Challenge: Caching Solutions: • Update one server while others handle load • Group servers and update group at a time • execute commands on “finalize” to clear up APC cacheSaturday, September 15, 2012
  46. 46. Deployment: Challenges Challenge: File permission conflicts Solutions: • Run Apache/PHP with same user • Use php-fpm instead of mod_php • Create “deploy” user and add web server to the group • Use setfacl to give write access to multiple usersSaturday, September 15, 2012
  47. 47. PHP Apps Deployment: Other common pitfallsSaturday, September 15, 2012
  48. 48. PHP Apps Deployment: Other common pitfalls • Case sensitive filesystems • Configuration differences • Outdated 3rd party software • Github down $ git daemon --base-path=/git/repo/path/ -- export-all $ git clone git://127.0.0.1/repo http://ozmm.org/posts/when_github_goes_down.htmlSaturday, September 15, 2012
  49. 49. PHP Apps Deployment: ExamplesSaturday, September 15, 2012
  50. 50. PHP Apps Deployment: Examples Simplest continuous deployment ever! hook.php <?php exec(ʻ/usr/bin/env -i HOME=/var/www git pullʼ); echo “All done!”; screenshotSaturday, September 15, 2012
  51. 51. PHP Apps Deployment: Examples Capistrano • Ruby based • Very extensible • Large number of extensions • Simple client side installation $ gem install capistranoSaturday, September 15, 2012
  52. 52. PHP Apps Deployment: Examples Capistrano set :application, "myapp" # Application name set :deploy_to, "/var/www/myapp" set :user, "deployer" set :use_sudo, false # sudo isnt required set :deploy_via, :remote_cache set :repository, "git@github.com:user/repo.git" role :web, "server.example.com", “server2.example.com”Saturday, September 15, 2012
  53. 53. PHP Apps Deployment: Examples Capistrano $ cap deploy $ cap deploy:migrations $ cap deploy:rollbackSaturday, September 15, 2012
  54. 54. PHP Apps Deployment: Examples Capifony (Symfony2) • Extension of Capistrano • Implements lots of needed features for Symfony • Great documentationSaturday, September 15, 2012
  55. 55. PHP Apps Deployment: Examples Capifony (Symfony2) $ capifony .Saturday, September 15, 2012
  56. 56. PHP Apps Deployment: Examples Capifony (Symfony2) set :keep_releases, 3 # directories that will be shared between all deployments set :shared_children, [ app_path + "/logs", web_path + "/ uploads"] set :update_vendors, true # set :use_composer, true set :dump_assetic_assets, trueSaturday, September 15, 2012
  57. 57. PHP Apps Deployment: Examples Capifony (Symfony2) $ cap deploy:setupSaturday, September 15, 2012
  58. 58. PHP Apps Deployment: Examples Capifony (Symfony2) |-- httpdocs | `-- index.php |-- releases `-- shared |-- logs `-- uploads 5 directories, 1 fileSaturday, September 15, 2012
  59. 59. PHP Apps Deployment: Examples Capifony (Symfony2) $ cap deploy $ cap deploy:migrations $ cap deploy:rollbackSaturday, September 15, 2012
  60. 60. PHP Apps Deployment: Other options • Fabric • WePloy • Phing • Magallanes • JenkinsSaturday, September 15, 2012
  61. 61. PHP Apps Deployment: ToolsSaturday, September 15, 2012
  62. 62. PHP Apps Deployment: Tools App Metrics: StatsD & GraphiteSaturday, September 15, 2012
  63. 63. PHP Apps Deployment: Tools Logging: Logstash Ship logs from any source, parse them, get the right timestamp, index them, and search themSaturday, September 15, 2012
  64. 64. PHP Apps Deployment: Tools Logging: Logstash Configure Apache to log json LogFormat "{ "@timestamp": "%{%Y-%m-%dT%H:%M:%S%z}t", "@fields": { "client": "%a", "duration_usec": %D, "status": %s, "request": "%U%q", "method": "%m", "referrer": "% {Referer}i" } }" logstash_json # Write our logstash_json logs to logs/access_json.log CustomLog logs/access_json.log logstash_json Result { "@timestamp": "2012-08-22T14:35:19-0700", "client": "127.0.0.1", "duration_usec": 532, "status": 404, "request": "/favicon.ico", "method": "GET", "referrer": "-" }Saturday, September 15, 2012
  65. 65. PHP Apps Deployment: Tools Logging: GraylogSaturday, September 15, 2012
  66. 66. PHP Apps Deployment: Tools Logging: Kibana Kibana is a user friendly way to view, search and visualize your log dataSaturday, September 15, 2012
  67. 67. PHP Apps Deployment: Tools Packaging: fpm Build packages for multiple platforms (deb, rpm, etc) with great ease and sanity. fpm -s dir -t rpm -n "myapp" -v 1.0 /var/www/myapp fpm -s dir -t deb -a all -n myapp -v 1.0 /etc/apache2/ conf.d/my.conf /var/www/myapp https://github.com/jordansissel/fpmSaturday, September 15, 2012
  68. 68. PHP Apps Deployment: Time for demoSaturday, September 15, 2012
  69. 69. PHP Apps Deployment: SummarySaturday, September 15, 2012
  70. 70. •Stop using FTPSaturday, September 15, 2012
  71. 71. •Stop using FTP •Plan earlySaturday, September 15, 2012
  72. 72. •Stop using FTP •Plan early •PracticeSaturday, September 15, 2012
  73. 73. •Stop using FTP •Plan early •Practice •MonitorSaturday, September 15, 2012
  74. 74. •Stop using FTP •Plan early •Practice •Monitor •AUTOMATE!Saturday, September 15, 2012
  75. 75. Thank you! QUESTIONS? Rate Me Please! https://joind.in/7079 Slides: http://slideshare.net/pgodel Twitter: @pgodel E-mail: pablo@servergrove.comSaturday, September 15, 2012

×