Deploying PHP applications to Platform as a Service (PaaS) can provide several benefits over traditional hosting methods. PaaS allows developers to quickly deploy new environments for testing code changes. It also handles tasks like optimizing stacks, upgrading software, and providing comprehensive routing. PaaS aims to make deployment as simple as uploading code and eliminates the need to manually configure servers. While there is an initial learning curve to using PaaS tools and reworking some applications, it can improve the development to production workflow and allow applications to easily scale on demand.
3. Outline
â˘âŻ PHP deployment "back then"
o⯠a (biased) history
â˘âŻ PHP deployment today
o⯠unresolved issues
â˘âŻ How PaaS can help
o⯠any PaaSânot just dotCloud! âş
â˘âŻ How to help yourself with PaaS
o⯠and make your lives (as developers) easier
â˘âŻ What's next?
4. Who am I? Who was I?
â˘âŻ Sysadmin in a (French) PHP shop
during the "dotcom bubble" (1999-2001)
â˘âŻ What did it mean to "create a site?"
o⯠Apache <VirtualHost> section
o⯠FTP account
o⯠MySQL database
o⯠sendmail aliases (hellyeah!)
o⯠DNS zone
â˘âŻ What did it mean to "go to production?"
o⯠Easy! Update the <VirtualHost>
5. The awful truth
â˘âŻ Repetitive tasks are error-prone
o⯠Script everything!
â˘âŻ Custom setups are error-prone
o⯠Knowing where to differentiate is black magic
â˘âŻ Moving developmentâproduction is easy
o⯠Having development+production is hard
A production environment is a customized, repeat version
of the development environment.
I don't see how anything could possibly go wrong.
6. PaaS 2000:
Account creation
â˘âŻ Summer 1999: Apache mod_vhost_alias
(Apache 1.3.7/1.3.9)
o⯠Create a directory, boom, you're done!
â˘âŻ April 1999: proftpd mod_mysql
("experimental and utterly undocumented")
o⯠INSERT a user, boom, you're done!
â˘âŻ Postfix virtual domains
o⯠With all due respect, sendmail was creepy
â˘âŻ BIND generic zones (PowerDNS later)
Bliss level: 9000!
7. PaaS 2000:
Go to production
â˘âŻ Move directories, rename users
o⯠Error prone!
â˘âŻ Create a new, clean account; copy DB
o⯠Different from the dev environment!
Whatever you do: if you push the wrong code
to the wrong place, something hits the fan.
8. PaaS 2000:
Musings with SQLite
â˘âŻ In May 2000, two great things happen:
PHP4 and SQLite.
â˘âŻ Deployment of simple PHP apps is easy:
Just upload the code. No DB creation.
â˘âŻ Migration of said PHP apps is easy:
Just copy the code (and the .db file).
â˘âŻ As long as you have this non-standard PHP.
â˘âŻ And you don't mind blewing up the DB.
11. PaaS 2000:
It's Web Scale!
â˘âŻ No load balancer yet, DNS round robin
o⯠Then HAProxy arrived, and Nginx, and F5...
â˘âŻ Files (PHP and static assets) over NFS
o⯠Today, we could talk about GlusterFS, S3...
â˘âŻ User accounts shared with NIS
o⯠LDAP is the new cool (... kind of)
â˘âŻ MySQL: no replication yet
o⯠But if you like, we can talk about 3-way multi-master
12. PaaS 2000:
The Downfall
"We need this Java thing"
â˘âŻmod_jk, mod_jserv, mod_ajp, ...
"And media streaming, too"
â˘âŻrealserver, ...
Those things were changing quickly.
We needed test environments.
Virtualization wasn't there yet.
âš
14. Let's talk about you!
Please raise your hand if you...
â˘âŻ Write PHP code?
â˘âŻ Use (mainly) FTP to deploy?
â˘âŻ Use SCP/rsync/similar to deploy?
â˘âŻ Use capistrano/fabric/similar to deploy?
â˘âŻ Deploy to a PaaS?
â˘âŻ Deploy to something else?
â˘âŻ Always use a staging environment?
â˘âŻ Have a clean stagingâproduction workflow?
15. What I do today
â˘âŻ Server-whisperer for dotCloud
o⯠...Among other things
â˘âŻ Tackling the PaaS challenge again
o⯠developmentâproduction workflow
o⯠deployment should be as easy as "upload, done!"
o⯠... even when $language
 !=
 "php"
Â
â˘âŻ Trying to steal NetBSD's motto
o⯠"Of course it runs on dotCloud"
18. Waitaminute...
What's a PaaS?
You The Great
Internet
Load balancer Load balancer
Tools:
CLI, API...
A large number of
beefy servers running apps
19. PaaS:
What's the point? (1/5)
Deploying new environments ...
â˘âŻ It's fast!
o⯠In minutes, you have your whole stack,
complete with DB, memcached, bells & whistles
o⯠Cool to test some now code
o⯠Or to deploy older code to find regressions
â˘âŻ It's cheap!
o⯠On most PaaS, development = free
20. PaaS:
What's the point? (2/5)
Leverage git, hg, ...
â˘âŻ If you don't know git, I beg you to attend
Mike Stowe's talk in Room 62 at 10:30am!
â˘âŻ Keep all versions of your code, ever;
go back to any of them
â˘âŻ Redeploy the exact version which was online last week
before that horrible bug happened
â˘âŻ Compare conversion rates on two variants
of your site
21. PaaS:
What's the point? (3/5)
Someone else takes care of ...
â˘âŻ Optimizing your stack (â code)
o⯠Crafting that crazy Nginx/PHP-FPM setup
o⯠Lower memory footprint
o⯠Better performance (APC...)
â˘âŻ Upgrading your stack
o⯠Watch security disclosure mailing lists
o⯠Roll out performance and security updates
o⯠Give you new versions of PHP, MySQL, etc.
22. PaaS:
What's the point? (4/5)
Comprehensive HTTP routing
â˘âŻ Attach/detach domains (virtualhosts)
o⯠Easy transitions to new versions
(And you keep the old version around)
â˘âŻ Get nice metrics
o⯠Request rate, error rate, latency
o⯠(See screenshots!)
â˘âŻ WebSocket support
o⯠And other languages as well
23.
24.
25. PaaS:
What's the point? (5/5)
Be Web Scale!
â˘âŻ Scale horizontally and vertically
o⯠horizontally = more servers
o⯠vertically = bigger servers
â˘âŻ Reliability
o⯠horizontal scaling for web tier
o⯠replication for database tier
â Deploy to the Cloud
26.
27. PaaS:
What's the point? (5/5)
Be Web Scale!
â˘âŻ Scale horizontally and vertically
o⯠horizontally = more servers
o⯠vertically = bigger servers
â˘âŻ Reliability
o⯠horizontal scaling for web tier
o⯠replication for database tier
â Deploy to the Cloud without the hassle
28. How to deploy PHP to
PaaS
Note: my example will use dotCloud.
But the principle is the same on any PAAS.
29. Deployment example:
Symfony2 "KnpIpsum"
Original code:https://github.com/KnpLabs/KnpIpsum
Â
dotCloudized version:https://github.com/jpetazzo/
KnpIpsum/tree/dotcloud
Â
(Make sure you use the "dotcloud" branch)
30. To the Cloud, and beyond!
0: setup environment
â˘âŻ Create (free) account on www.dotcloud.com
â˘âŻ Install Python (!)
â˘âŻ pip
 install
 dotcloud
Â
â˘âŻ dotcloud
 setup(Asks for login+password)
(Note: web-based push is ââ that close)
31. To the Cloud, and beyond!
1: dotcloud.yml
Â
â˘âŻ The app is described by a small YAML file
www:
Â
Â
 type:
 php
Â
Â
 approot:
 web
Â
mongodb:
Â
Â
 type:
 mongodb
Â
mysql:
Â
Â
 type:
 mysql
Â
32. To the Cloud, and beyond!
2: dotCloud+Symfony2
â˘âŻ dotCloud has Symfony2 docs
â˘âŻ The docs tell us we need a nginx.conf file
â˘âŻ That's because most people deploy
Symfony2 on Apache + mod_php
â˘âŻ Symfony2 apps typically ship .htaccess
 file
â˘âŻ We need the equivalent of that file
â Drop nginx.conf file in the web directory.
33. To the Cloud, and beyond!
3: application specifics
â˘âŻ README says to run a few manual
steps:bin/vendors
 install
Â
php
 app/console
 doctrine:database:create
Â
php
 app/console
 doctrine:schema:create
Â
â˘âŻ We will put those steps in a postinstall script
(that's just a shell script called "postinstall"),
and the postinstall script will be executed
automatically when we deploy
34. To the Cloud, and beyond!
4: deploy application
$
 dotcloud
 create
 symfonipsum
Â
[...]
Â
$
 dotcloud
 push
Â
==>
 Pushing
 code
 with
 rsync
 from
 "./"
 to
 application
 symfonipsum
Â
building
 file
 list
 ...
 done
Â
[...uploading...]
Â
[...and
 a
 couple
 of
 minutes
 later...]
Â
14:38:10.312838:
 -Ââ-Ââ>
 Application
 (symfonipsum)
 fully
 installed
Â
==>
 Application
 is
 live
 at
 http://symfonipsum-Ââskaya.dotcloud.com
Â
But of course, it doesn't work:
we never configured the database host/port/etc.
35. To the Cloud, and beyond!
5: configure database
â˘âŻ Find out database information:
$
 dotcloud
 info
 mysql
Â
[...]
Â
ports:
Â
Â
 ssh:
Â
Â
 ssh://mysql@symfonipsum-Ââskaya.azva.dotcloud.net:12345
Â
Â
 mysql:
 mysql://root:XXX@symfonipsum-Ââskaya.azva.dotcloud.net:23456
Â
â˘âŻ Edit app/config/config.yml,
update host/port/login/password
â˘âŻ Push again
36. Quick break:
"The Twelve Factor App"
â˘âŻ http://www.12factor.net/
â˘âŻ http://www.12factor.net/config
â˘âŻ "Store config in the environment"
o⯠App config = everything that is likely to vary between deploys
(staging, production, developer env., etc.)
o⯠Includes: database/memcached access information,
credentials to external services (Twitter, S3...)
o⯠Storing config as constants in the code is wrong! Please don't
do it!
o⯠A good test: can you open source the code without
compromising any credential?
37. To the Cloud, and beyond!
5bis: configure database
â˘âŻ dotCloud will put all information in two files:
o⯠~/environment.json
Â
o⯠~/environment.yml
Â
â˘âŻ We do the following changes:
o⯠Update postinstall to generate ~/symfony.yml (using the
information in environment.json)
o⯠Update app/config/config.yml to import ~/symfony.yml
Â
â˘âŻ Push again
38. To the Cloud, and beyond!
6: Multiplicate the Loaves
$
 dotcloud
 create
 ipsumdev
Â
$
 dotcloud
 push
Â
[...]
Â
$
 dotcloud
 create
 symfonymongotest
Â
$
 dotcloud
 push
Â
[...]
Â
39. To the Cloud, and beyond!
7: Go live!
$
 dotcloud
 create
 ipsumprod
 -Ââf
 live
Â
$
 dotcloud
 push
Â
$
 dotcloud
 scale
 db:instances=2
Â
$
 dotcloud
 scale
 www:memory=800M
Â
$
 dotcloud
 domain
 add
 www
 www.loremipsum.com
Â
40. Drawbacks of PaaS
â˘âŻ One-time initial investment (small)
o⯠Get familiar with the CLI, tools...
â˘âŻ Per-app initial investment (variable)
o⯠Inject configuration variables
o⯠Rework your app "for the Cloud" (when needed)
o⯠Meddle Not In The Affairs Of Wizards!
41.
42. Drawbacks of PaaS
â˘âŻ One-time initial investment (small)
o⯠Get familiar with the CLI, tools...
â˘âŻ Per-app initial investment (variable)
o⯠Inject configuration variables
o⯠Rework your app "for the Cloud" (when needed)
o⯠Meddle Not In The Affairs Of Wizards!
â˘âŻ Higher apparent cost
o⯠PaaS hosting can be 4x-10x more expensive
o⯠Comes with 24x7 ops team, scaling, support
o⯠Current PaaS don't leverage cheap hosts yet
43. One more (semi-)
Drawback of PaaS
â˘âŻ "dotcloud
 run" (SSH access) doesn't work on the
WiFi access in this conference!
â˘âŻ But we're working on that...
(WebSocket tunneling of SSH)
â˘âŻ And you can't access your server, neither.
(Unless you have a cunning VPN;
OpenVPN running on 443/tcp anyone?)
â˘âŻ Meawhile, you can still push to dotCloud! Yaaay!
44. Future of PaaS
â˘âŻ PaaS on your servers / local machine
â˘âŻ PaaS on a wide range of platforms
(from cheap entry-level to high-end SSD)
â˘âŻ Support for more languages & databases
â˘âŻ Support for more frameworks
â˘âŻ More integration with 3rd parties (e.g. github)