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.
10. Deployment
Software deployment is all of the activities that !
make a software system available for use.
http://en.wikipedia.org/wiki/Software_deployment
57. Deployment Fact #1
Deployment starts with the developer
• Development environment must be as close as
possible to productions servers!
58. Deployment Fact #1
Deployment starts with the developer
• Development environment must be as close as
possible to productions servers!
• Setup test/qa/staging servers!
59. Deployment Fact #1
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!
60. Deployment Fact #1
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!
61. Deployment Fact #1
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)
63. Deployment Fact #2
Success depends on server OS setup
• Automate installation/configuration with Ansible/
Puppet/Chef !
64. Deployment Fact #2
Success depends on server OS setup
• Automate installation/configuration with Ansible/
Puppet/Chef !
• Create OS packages for 3rd party software
65. Deployment Fact #2
Success depends on server OS setup
• Automate installation/configuration with Ansible/
Puppet/Chef !
• Create OS packages for 3rd party software!
• Setup your own package (rpm/deb) repositories
67. Deployment Fact #3
Monitoring is uptime
• Use tools to know what is going on with your
servers (Ganglia, Cacti, Zabbix, etc.)!
68. Deployment Fact #3
Monitoring is uptime
• Use tools to know what is going on with your
servers (Ganglia, Cacti, Zabbix, etc.)!
69. Deployment Fact #3
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)!
70. Deployment Fact #3
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)
82. Deployment: First time
• Copy files to server(s)!
• Set server-side configurations!
• Load DB fixtures!
• Process and install assets!
• Warm up cache!
• Enable site
83. 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
89. Deployment Challenges
Challenge: Secure
• use ssh based connections!
• don’t store passwords on source control!
• use environment variables for sensitive data
93. Deployment Challenges
Challenge: Static assets
• Minimize/combine JS and CSS files!
• Enable web server compression!
• Add versioning to static assets links (code.js?v=1)!
94. Deployment Challenges
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!
95. Deployment Challenges
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
99. Deployment Challenges
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
100. Deployment Challenges
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!
101. Deployment Challenges
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
115. Deployment Examples
Capistrano / Capifony
• Ruby based!
• Very extensible!
• Large number of extensions!
• Simple client side installation
116. Deployment Examples
Capistrano / Capifony
• Ruby based!
• Very extensible!
• Large number of extensions!
• Simple client side installation
$ gem install capifony!
117. Deployment Examples
Capistrano / Capifony
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”
133. Deployment Complement Tools
App Metrics: liuggio/statsd-php-client
$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);
134. Deployment Complement Tools
App Metrics: liuggio/statsd-php-client
$data[] = $factory->timing('usageTime', 100);!
!
// send the data as array or directly as object
$client->send($data);
135. Deployment Complement Tools
App Metrics: liuggio/statsd-php-client
$data[] = $factory->increment('orders');!
!
// send the data as array or directly as object
$client->send($data);
136. Deployment Complement Tools
App Metrics: liuggio/statsd-php-client
$data[] = $factory->gauge('memory', 333);!
!
// send the data as array or directly as object
$client->send($data);
140. Deployment Complement Tools
Logging: Logstash
Ship logs from any source, parse them, get the right
timestamp, index them, and search them
input {
file {
path => “/var/log/apache2/access_log”
}
}
output {
elasticsearch {
host => localhost
}
}
164. Docker
Deployment Future
Host
Docker client
C
VM
Web
Server
C C
DB
Server
App
Server
Host
C
VM
Web
Server
C C
DB
Server
App
Server
165. Docker
Deployment Future
Host
Docker client
C
VM
Web
Server
C C
DB
Server
App
Server
Host
C
VM
Web
Server
Host
C C
DB
Server
C C
App
Server
C
Web
Server
DB
Server
App
Server
Docker
Kernel