Declare independence from your it department sysadmin skills for symfony dev...
Rock Solid Deployment of Web Applications
1. Rock Solid Deployment
of Web Applications
Pablo Godel @pgodel - codemiami.com
Jan 12th 2013 - Miami, FL
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
⁃ Co-founder of ServerGrove
3.
4. ServerGrove!
⁃ Founded ServerGrove Networks in 2005
⁃ Provider of web hosting specialized in PHP,
Symfony, ZendFramework, MongoDB and others
⁃ Servers in USA (right here in Miami) and Europe!
5. Community is our teacher
⁃ Very active open source supporter through code
contributions and usergroups/conference sponsoring
7. Deployment
Software deployment is all of the activities that make
a software system available for use.
http://en.wikipedia.org/wiki/Software_deployment
29. 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/
configuration
30. 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 repositories
31. 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)
35. 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” site
36. Web Apps Deployment:
Subsequent times
• Copy files to server(s)
• Apply DB updates (migrations)
• Process and install assets
• Warm up cache
• “Enable” site
38. 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)
39. 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 servers
43. 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
result
45. 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 users
50. Web Apps Deployment:
Examples
Capistrano
• Ruby based
• Very extensible
• Large number of extensions
• Simple client side installation
$ gem install capistrano
51. Web Apps Deployment:
Examples
Capistrano
set :application, "myapp" # Application name
set :deploy_to, "/var/www/myapp"
set :user, "deployer"
set :use_sudo, false # sudo isn't required
set :deploy_via, :remote_cache
set :repository, "git@github.com:user/repo.git"
role :web, "server.example.com", “server2.example.com”
62. Web Apps Deployment:
Tools
Logging: Kibana
Kibana is a user friendly way to view, search and visualize
your log data
63. Web 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/fpm