4/12 MAIN FACTORS, CODE ACCORDINGLY I. Codebase From one codebase, perform many deploys to staging, prod, ... II. Dependencies Your application explicitly declares userland and platform deps. III. Configuration Read from $_ENV: API keys, database credentials, SMTP hosts, ... XI. Logging file_put_contents("php://stderr",
"Yay
log");
III. CONFIGURATION Store config in the environment. $transport
=
Swift_SmtpTransport::newInstance(
getenv('EMAIL_HOST'),
getenv('EMAIL_PORT')?:25 )
-‐>setUsername(getenv('EMAIL_USERNAME'))
-‐>setPassword(getenv('EMAIL_PASSWORD')) ; Assumption: same code but different configuration per deployment target $
heroku
config:set
EMAIL_HOST=smtp.blah.com
EMAIL_PORT=827
\
EMAIL_USERNAME=joecool
EMAIL_PASSWORD=itwasadarkandstormynight
III. CONFIGURATION Store config in the environment. $smtp
=
parse_url(getenv('SMTP_GATEWAY_URL'));
$transport
=
Swift_SmtpTransport::newInstance(
$smtp['host'],
$smtp['port'] )
-‐>setUsername($smtp['user'])
-‐>setPassword($smtp['pass']) ; Assumption: same code but different configuration per deployment target $
heroku
config:set
SMTP_GATEWAY_URL=\
smtp://joecool:[email protected]:827
V. BUILD, RELEASE, RUN A build step vendors dependencies, prepares assets, etc. A release step creates a package from build and config. A runtime step executes, without special knowledge.
V. BUILD, RELEASE, RUN A build step vendors dependencies, prepares assets, etc. A release step creates a package from build and config. A runtime step executes, without special knowledge.
X. DEV/PROD PARITY Keep dev, stage and prod envs as similar as possible. SQLite ≠ MySQL Apache ≠ Nginx File based sessions ≠ Redis based sessions If apt-‐get or brew don't get the job done on your box: Vagrant is always your friend!
VI. PROCESSES heroku-‐php-‐app
$
cat
Procfile
worker:
php
background.php
web:
vendor/bin/heroku-‐php-‐apache2
#
or
heroku-‐php-‐nginx automatically injected into the app during build
XII. ADMIN PROCESSES Management tasks like DB migrations are one-off processes. They run in isolation, just like all other "dynos". With the same release: same code, same config!
XII. ADMIN PROCESSES Management tasks like DB migrations are one-off processes. $
heroku
run
"php
app/console
doctrine:migrations:migrate" Running
`php
app/console…`
attached
to
terminal...
up,
run.4062
Migrating
up
to
20100416130452
from
0
>>
migrating
20100416130452
-‐>
CREATE
TABLE
users
(username
VARCHAR(255)
NOT
NULL,
password
VARCHAR(255)
NOT
NULL)
ENGINE
=
InnoDB
>>
migrated They run in isolation, just like all other "dynos". With the same release: same code, same config!