Web applications are becoming increasingly more complex, so deployment is not just transferring files with FTP anymore. We will go over the different challenges and how to deploy our PHP applications effectively, safely and consistently with the latest tools and techniques. We will also look at tools that complement deployment with management, configuration and monitoring.
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
Tuesday, July 16, 13
4. Deployment
Software deployment is all of the activities that make
a software system available for use.
http://en.wikipedia.org/wiki/Software_deployment
Tuesday, July 16, 13
26. 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
Tuesday, July 16, 13
27. 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
Tuesday, July 16, 13
28. 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)
Tuesday, July 16, 13
32. 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
Tuesday, July 16, 13
33. • Copy files to server(s)
• Apply DB updates (migrations)
• Process and install assets
• Warm up cache
• “Enable” site
Web Apps Deployment:
Subsequent times
Tuesday, July 16, 13
35. Deployment: Challenges
• rsync
• git pull
• setup git repo on local network to save
bandwidth and avoid issues if git server is down
(i.e. github)
Challenge:
Fast & reliable copy of files
Solutions:
Tuesday, July 16, 13
36. Deployment: Challenges
• 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
Challenge:
Scalable
Solutions:
Tuesday, July 16, 13
37. Deployment: Challenges
• test!
• tag releases
• dedicated branches (master for production)
• deploy each release in its own directory
Challenge:
Rollbacks
Solutions:
Tuesday, July 16, 13
38. Deployment: Challenges
• use ssh based connections
• don’t store passwords on source control
• store sensitive strings (passwords) in server
environment variables
Challenge:
Secure
Solutions:
Tuesday, July 16, 13
40. 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
Tuesday, July 16, 13
42. 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
Tuesday, July 16, 13
47. Web Apps Deployment:
Examples
Capistrano
• Ruby based
• Very extensible
• Large number of extensions
• Simple client side installation
$ gem install capistrano
Tuesday, July 16, 13
48. 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”
Tuesday, July 16, 13
56. Web Apps Deployment:
Tools
Logging: Logstash
Ship logs from any source, parse them, get the right
timestamp, index them, and search them
Tuesday, July 16, 13
60. Web Apps Deployment:
Tools
Packaging: fpm
https://github.com/jordansissel/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
Tuesday, July 16, 13