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.
6. Deployment
Software deployment is all of the activities that !
make a software system available for use.
http://en.wikipedia.org/wiki/Software_deployment
53. Deployment starts with the developer
• Development environment must be as close as
possible to productions servers!
Deployment Fact #1
54. Deployment starts with the developer
• Development environment must be as close as
possible to productions servers!
• Setup test/qa/staging servers!
Deployment Fact #1
55. Deployment starts with the developer
• Development environment must be as close as
possible to productions servers!
• Setup test/qa/staging servers!
• Use Vagrant to manage VMs!
Deployment Fact #1
56. Deployment starts with the developer
• Development environment must be as close as
possible to productions servers!
• Setup test/qa/staging servers!
• Use Vagrant to manage VMs!
• Use Containers with Docker!
Deployment Fact #1
57. Deployment starts with the developer
• Development environment must be as close as
possible to productions servers!
• Setup test/qa/staging servers!
• Use Vagrant to manage VMs!
• Use Containers with Docker!
• Automate your development environment setup
(Ansible, Homebrew Cask)
Deployment Fact #1
59. Success depends on server OS setup
• Automate installation/configuration with Ansible/
Puppet/Chef !
Deployment Fact #2
60. • Automate installation/configuration with Ansible/
Puppet/Chef !
• Create OS packages for 3rd party software
Deployment Fact #2
Success depends on server OS setup
61. • Automate installation/configuration with Ansible/
Puppet/Chef !
• Create OS packages for 3rd party software!
• Setup your own package (rpm/deb) repositories
Deployment Fact #2
Success depends on server OS setup
63. Monitoring is uptime
• Use tools to know what is going on with your
servers (Ganglia, Cacti, Zabbix, etc.)!
Deployment Fact #3
64. Monitoring is uptime
• Use tools to know what is going on with your
servers (Ganglia, Cacti, Zabbix, etc.)!
Deployment Fact #3
65. Monitoring is uptime
• Use tools to know what is going on with your
servers (Ganglia, Cacti, Zabbix, etc.)!
• Add metrics to your app (Graphite, StatsD, New
Relic)!
Deployment Fact #3
66. Monitoring is uptime
• Use tools to know what is going on with your
servers (Ganglia, Cacti, Zabbix, etc.)!
• Add metrics to your app (Graphite, StatsD, New
Relic)!
• Use your logs wisely (Logstash, Hecka, Kibana)
Deployment Fact #3
78. Deployment: First time
• Copy files to server(s)!
• Set server-side configurations!
• Load DB fixtures!
• Process and install assets!
• Warm up cache!
• Enable site
79. Deployment: Subsequent times
• Copy files to server(s)!
• Update server-side configurations!
• Update DB (migrations)!
• Process and install assets!
• Warm up cache!
• Enable new version
83. • use ssh based connections!
Challenge: Secure
Deployment Challenges
84. • use ssh based connections!
• don’t store passwords on source control
Challenge: Secure
Deployment Challenges
85. • use ssh based connections!
• don’t store passwords on source control!
• use environment variables for sensitive data
Challenge: Secure
Deployment Challenges
88. Challenge: Static assets
• Minimize/combine JS and CSS files!
• Enable web server compression!
Deployment Challenges
89. Challenge: Static assets
• Minimize/combine JS and CSS files!
• Enable web server compression!
• Add versioning to static assets links (code.js?v=1)!
Deployment Challenges
90. Challenge: Static assets
• Minimize/combine JS and CSS files!
• Enable web server compression!
• Add versioning to static assets links (code.js?v=1)!
• Run utilities locally or in a staging server, create
artifact, deploy result!
Deployment Challenges
91. Challenge: Static assets
• Minimize/combine JS and CSS files!
• Enable web server compression!
• Add versioning to static assets links (code.js?v=1)!
• Run utilities locally or in a staging server, create
artifact, deploy result!
• Serve static files from subdomain / CDN
Deployment Challenges
94. Challenge: File permission conflicts
• Run Apache/PHP with same user!
• Use php-fpm instead of mod_php!
Deployment Challenges
95. Challenge: File permission conflicts
• Run Apache/PHP with same user!
• Use php-fpm instead of mod_php!
• Create “deploy” user and add web server to the
group
Deployment Challenges
96. Challenge: File permission conflicts
• 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!
Deployment Challenges
97. Challenge: File permission conflicts
• 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!
• Use external services for writing files and create
readonly installations
Deployment Challenges
111. Capistrano / Capifony
• Ruby based!
• Very extensible!
• Large number of extensions!
• Simple client side installation
Deployment Examples
112. • Ruby based!
• Very extensible!
• Large number of extensions!
• Simple client side installation
$ gem install capistrano!
Deployment Examples
Capistrano / Capifony
113. 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”
Deployment Examples
Capistrano / Capifony
129. App Metrics: liuggio/statsd-php-client
Deployment Complement Tools
$sender = new SocketSender(/*'localhost', 8126, 'udp'*/);
!
$client = new StatsdClient($sender);
$factory = new StatsdDataFactory('LiuggioStatsdClientEntityStatsdData');
!
// create the data with the factory
$data[] = $factory->timing('usageTime', 100);
$data[] = $factory->increment('visitor');
$data[] = $factory->decrement('click');
$data[] = $factory->gauge('gaugor', 333);
$data[] = $factory->set('uniques', 765);
!
// send the data as array or directly as object
$client->send($data);
136. Logging: Logstash
Ship logs from any source, parse them, get the right
timestamp, index them, and search them
Deployment Complement Tools
input {
file {
path => “/var/log/apache2/access_log”
}
}
output {
elasticsearch {
host => localhost
}
}