Cloud Foundry for PHP developers

4,528 views

Published on

At this joint NYC Cloud Foundry and NY PHP meetup, we'll discuss the shift to Platform-as-a-Service and what it means for PHP development on the cloud.

First, we'll take a look at the "traditional" cloud Infrastructure-as-a-Service (virtual servers and disks) model and describe how Platform-as-a-Service builds upon it to provide the runtimes and data services for hosting PHP applications.

We'll then demonstrate how a PHP developer can use buildpacks and services within a Cloud Foundry PaaS to deploy scalable and resilient apps to his or her cloud of choice.

Along the way we'll compare the variety of buildpacks available to PHP developers, show techniques for binding to services, and highlight best practices for creating born-on-the-cloud apps based on a microservices architecture.

Special thanks to Dan Mikusa for helping with the buildpack comparison.

PHP developers: Please give all three build packs a try. Provide your feedback and submit pull requests on GitHub.

Published in: Technology
2 Comments
8 Likes
Statistics
Notes
  • @Dileep K. Sharma Hi Dileep, in the case of the Mikusa buildpack, which has now sensibly replaced the Heroku buildpack as the default, you can find web server configuration docs here: https://github.com/cloudfoundry/php-buildpack/blob/master/docs/usage.md For others, if you want to use the Mikusa buildpack (and your version of Cloud Foundry does not yet include it as the default), use the following -b switch on cf push or in your manifest.yml: cf push -b https://github.com/cloudfoundry/php-buildpack.git my-php-app
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • How can I load any specific module using cloud foundry. I want enable mod_rewrite module on my Bluemix website.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
4,528
On SlideShare
0
From Embeds
0
Number of Embeds
255
Actions
Shares
0
Downloads
105
Comments
2
Likes
8
Embeds 0
No embeds

No notes for slide

  • 12factor.net (http://12factor.net)
    Martin Fowler on Microservices Architecture (http://martinfowler.com/articles/microservices.html)
    ActiveState blog (http://www.activestate.com/blog/2014/08/microservices-and-paas-part-i)

    Matt Stine’s CF Summit presentation (http://www.slideshare.net/mstine/microservices-cf-summit)
  • http://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html
  • As you decompose monolithic applications and have them interact over REST APIs, you may run into an issue on PaaS which relies on subdomains. CORS.

    https://developer.ibm.com/bluemix/2014/07/17/cross-origin-resource-sharing-bluemix-apis/
  • Cloud Foundry for PHP developers

    1. 1. Cloud Foundry for PHP developers! Deploy apps built with the leading open source language to the leading open source Platform-as-a-Service ‹#› Daniel Krook! Senior Certified IT Specialist, IBM" @DanielKrook
    2. 2. Agenda § Cloud 101! ! § Introducing Cloud Foundry! ! § Demo: Simple PHP app push and MySQL bind! § Services in Cloud Foundry! § Buildpacks in Cloud Foundry! § Demo: Scaling and zero downtime deploys! § Considerations for designing PHP apps for the cloud! § Demo: Cross-origin resource sharing in microservices! § Where to go from here! ! github.com/krook ! slideshare.net/danielkrook !
    3. 3. Agenda § Cloud 101 § Introducing Cloud Foundry § Demo: Simple PHP app push and MySQL bind § Services in Cloud Foundry § Buildpacks in Cloud Foundry § Demo: Scaling and zero downtime deploys § Considerations for designing PHP apps for the cloud § Demo: Cross-origin resource sharing in microservices § Where to go from here ! Software defined environments! Cloud operating environment! API economy!
    4. 4. Software defined environments!Cloud operating environment!API economy! Infrastructure! Platform! Software! Applications! Data! Runtime! Middleware! O/S! Virtualization! Servers! Storage! Applications! Data! Runtime! Middleware! O/S! Virtualization! Servers! Storage! Sys admin (Ops)! App builder (Dev)! Business user (Biz)! Standardization; lower costs; faster time to value! Traditional ! on premise! Applications! Data! Runtime! Middleware! O/S! Virtualization! Servers! Storage! Networking! Networking! Networking! Applications! Data! Runtime! Middleware! O/S! Virtualization! Servers! Storage! Networking! Client manages!Vendor manages in cloud!
    5. 5. IaaS: the software defined data center Software defined environments! Infrastructure! Applications! Data! Runtime! Middleware! O/S! Virtualization! Servers! Storage! Networking! Ops!
    6. 6. PaaS: the cloud operating environment Cloud operating environment! Platform! Applications! Data! Runtime! Middleware! O/S! Virtualization! Servers! Storage! Networking! Dev!
    7. 7. SaaS: the API economy API economy! Software! Applications! Data! Runtime! Middleware! O/S! Virtualization! Servers! Storage! Networking! Biz! OAuth
    8. 8. The key benefits of Platform-as-a-Service for developers § There's no need to focus on provisioning, managing, or monitoring the compute, storage, network and software § Developers can create working prototypes in a matter of minutes. § Developers can create new versions or deploy new code more rapidly § Developers can self-assemble services to create integrated applications. § Developers can scale applications more elastically by starting more instances. § Developers don’t have to worry about underlying operating system and middleware security patches. § Developers can mitigate backup and recovery strategies, assuming the PaaS takes care of this. And the key disadvantages § Applications require a different architecture mindset § This requires developer skill and awareness of best practices and web app limitations. § Don’t have as much control over the underlying infrastructure. Security, versioning, performance considerations.
    9. 9. Agenda § Cloud 101 § Introducing Cloud Foundry § Demo: Simple PHP app push and MySQL bind § Services in Cloud Foundry § Buildpacks in Cloud Foundry § Demo: Scaling and zero downtime deploys § Considerations for designing PHP apps for the cloud § Demo: Cross-origin resource sharing in microservices § Where to go from here !
    10. 10. Cloud Foundry is the industry’s Open PaaS and provides a choice of clouds, frameworks and application services. Its unique vision is to foster contributions from a broad community of developers, users, customers, partners and ISVs while advancing development of the platform at extreme velocity. cloudfoundry.org
    11. 11. Frameworks and services lend Cloud Foundry its extensibility Buildpacks (implement frameworks for apps) detect compile release package The detect script is used to determine whether or not to apply the buildpack to an application. The compile script builds the droplet that will be run by the DEA and will therefore contain all the components necessary to run the application. The release script provides feedback metadata back to Cloud Foundry indicating how the application should be executed. The package script provides artifacts, which are provided to Cloud Foundry as system buildpacks. package is intended to provide a way for developers to package a buildpack with its dependencies. Brokered services (implement an API to provide services) fetch provision bind
    12. 12. Cloud Foundry is built on a highly scalable distributed architecture Routes incoming traffic to the appropriate component; generally the Cloud Controller or application Identity management service for the platform. Acts as an OAuth2 and SCIM provider. Monitors the state of applications and ensures that the correct number of instances are running Exposes a REST API to the system. Manages a database of apps, services, service instances, etc End user provided code that is “pushed” to the cloud and packaged to run in warden container Advertises service offerings to the Cloud Controller and handles requests to create, bind, unbind, and delete service instances. Managed by the service gateway, these nodes host service instances. A broker that can expose a service instance to a service managed outside of the cloud A collection of code that is responsible for transforming pushed app artifacts into a ready to run droplet A pub-sub message bus implemented with NATS that’s used for cross component communication Droplet Execution Agent – Advertises capacity to execute droplets created by a build pack A distributed deployment install and management tool that abstracts the details of the IaaS layer
    13. 13. Components collaborate via messaging and REST APIs
    14. 14. BOSH deploys and manages Cloud Foundry clusters on an IaaS Deployment Manifest • Release name/version • # VMs, Job params • Stemcells to use Stemcell • Base OS • BOSH Agent Release • Name Jobs • Software Packages • Config Templates • Scripts Deployed Environment irtual Machine • Configuration • Software Packages Virtual Machine • Configuration • Software Packages Virtual Machine • Configuration • Software Packages Virtual Machine • Configuration • Software Packages Stemcells In a cloud platform, VMs are usually cloned from a template. A stemcell is a VM template containing a standard Ubuntu distribution. A BOSH agent is also embedded in the template so that BOSH can take control of VMs cloned from the stemcell. Jobs A job is a collection of software which serves a particular purpose (e.g. MySQL or the Cloud Controller). At deployment time, each job will be install on its own stemcell VM. Releases A release contains a number of jobs which can be deployed into the target environment. A deployment can consist of more than one release and not every job in a release must be deployed.
    15. 15. The BOSH Cloud Provider Interface (CPI) manages the IaaS resources that Cloud Foundry needs Stemcells create_stemcell(image, cloud_properties) delete_stemcell(stemcell) Virtual Machines create_vm(agent_id, stemcell, resource_pool, networks, disk_locality, env) delete_vm(vm) reboot_vm(vm) configure_networks(vm, networks) Disks create_disk(size, vm_locality) delete_disk(disk) attach_disk(vm, disk) detach_disk(vm, disk)
    16. 16. Cloud Foundry distributions Hosted public § IBM Bluemix http://bluemix.net § Pivotal WS http://run.pivotal.io Self hosting § “Try Cloud Foundry” on AWS https://trycf.starkandwayne.com § BOSH bootstrap https://github.com/cloudfoundry-community/bosh-bootstrap § Deploy your own to AWS http://www.slideshare.net/SpringCentral/build-yourowncf http://docs.cloudfoundry.org/deploying/ec2/ § Install on on a laptop https://github.com/cloudfoundry/bosh-lite https://github.com/yudai/cf_nise_installer § Stackato Micro Cloud http://www.activestate.com/stackato/get_stackato Private § Pivotal CF http://run.pivotal.io
    17. 17. The Cloud Foundry Foundation
    18. 18. Cloud Foundry versus other Platforms-as-a-Service http://paasify.it http://bit.ly/pivotal-paas-compare ! http://bit.ly/altoros-paas-compare !
    19. 19. What about Docker? There are several projects underway to leverage Docker to host the Cloud Foundry PaaS, as well as the applications that run on it.
    20. 20. Agenda § Cloud 101 § Introducing Cloud Foundry § Demo: Simple PHP app push and MySQL bind § Services in Cloud Foundry § Buildpacks in Cloud Foundry § Demo: Scaling and zero downtime deploys § Considerations for designing PHP apps for the cloud § Demo: Cross-origin resource sharing in microservices § Where to go from here ! $ cf push my-php-app
    21. 21. Demo 1: PHP app push and debug § Download the Cloud Foundry CLI, log in and target your cloud § Clone meetup-cf-php-1 from https://github.com/krook/meetup-cf-php-1.git § Create index.php with syntax error § cf push meetup-cf-php-1 -m 128M -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git § Load page in browser: http://meetup-cf-php-1.mybluemix.net § cf logs meetup-cf-php-1 --recent § Fix syntax error in index.php! § cf push meetup-cf-php-1 § Load page in browser: http://meetup-cf-php-1.mybluemix.net
    22. 22. Demo 2: PHP app push and bind to MySQL § Clone meetup-cf-php-2 from https://github.com/krook/meetup-cf-php-2.git § cf push (uses the manifest.yml settings) § Load page in browser: http://meetup-cf-php-2.mybluemix.net § cf marketplace (view the services catalog) § cf create-service mysql 100 meetup-cf-mysql (provision a MySQL service) § cf services (view my service instances) § cf bind-service meetup-cf-php-2 meetup-cf-mysql (bind the MySQL instance to my PHP app) § cf restage meetup-cf-php-2 (make the service available in my VCAP_SERVICES env variable) § Load page in browser: http://meetup-cf-php-2.mybluemix.net
    23. 23. Agenda § Cloud 101 § Introducing Cloud Foundry § Demo: Simple PHP app push and MySQL bind § Services in Cloud Foundry § Buildpacks in Cloud Foundry § Demo: Scaling and zero downtime deploys § Considerations for designing PHP apps for the cloud § Demo: Cross-origin resource sharing in microservices § Where to go from here ! $ cf bind-service my-php-app mysql-srv
    24. 24. Cloud Foundry provides several community services
    25. 25. More services can be added with the Cloud Foundry service broker API
    26. 26. Cloud Foundry provides the framework to bind services to your apps
    27. 27. Sample service catalog from Cloud Foundry hosted providers IBM Bluemix (bluemix.net)! Pivotal WS (run.pivotal.io)! In addition to a catalog of data, queue, mail, log, push services, providers may offer auto-scaling and DevOps integration
    28. 28. Agenda § Cloud 101 § Introducing Cloud Foundry § Demo: Simple PHP app push and MySQL bind § Services in Cloud Foundry § Buildpacks in Cloud Foundry § Demo: Scaling and zero downtime deploys § Considerations for designing PHP apps for the cloud § Demo: Cross-origin resource sharing in microservices § Where to go from here ! $ cf push my-php-app –b git://…my-bp.git
    29. 29. The Cloud Foundry Heroku buildpack model Buildpacks implement execution environments for apps. They can be either a raw language (Java), or with frameworks (Spring, servlet, standalone). When pushed, the entire application is encapsulated into a “droplet” and is run in an isolated Linux container on the pool of “droplet execution agents.” bin/detect The detect script is used to determine whether or not to apply the buildpack to an application. bin/compile The compile script builds the droplet that will be run by the DEA and will therefore contain all the components necessary to run the application. bin/release The release script provides feedback metadata back to Cloud Foundry indicating how the application should be executed. bin/package The package script provides artifacts, which are provided to Cloud Foundry as system buildpacks. package is intended to provide a way for developers to package a buildpack with its dependencies. Scripts can be written in a variety of languages (bash, Python, Ruby, etc.)
    30. 30. Comparing the popular PHP buildpacks Source PHP version (default) Web server (default) Extensions (default) Memory (minimum) Notes Pivotal (Dan Mikusa) 5.4 (Latest 5.5 and 5.6 also supported) Apache (nginx and standalone apps also supported) Minimal set to start, lots of extensions supported and can be specified. 96 MB • Created from the ground up for Cloud Foundry, no Heroku legacy code • Supports offline mode • Supports Composer, but doesn’t require it • Very configurable (options.json). • Very actively improved and kept up to date. • Optimized to download as little as possible • Supports a wider variety of Ubuntu stem cells • Supports latest stable PHP 5.4, 5.5, 5.6 • Known to work with popular frameworks, such as CodeIgniter and Phalcon • Lots of samples • Supports other running processes • Apache 2 license Heroku (David Zuelke) 5.5 Apache (nginx also supported) Minimal 128 MB • Forked from Heroku, still compatible with Heroku • Supports offline mode • Requires you use Composer (or fake it) for dependencies • MIT license • Known to work with popular projects like WordPress • Will be built in to future versions of Cloud Foundry Zend 5.4 (Long term support through Zend Server 7) Apache All the same available in Zend Server 7 512 MB • Supported by Zend. • Provides the whole familiar Zend Server GUI. • Provides a consistent experience between CF and other cloud delivery models (IaaS, patterns) • Provides Zend value add: Z-Ray, monitoring, performance, audit trail, job queue • Requires MySQL
    31. 31. Pushing an app with a specific buildpack § Pivotal § cf push my-php-app -b https://github.com/dmikusa-pivotal/cf-php-build-pack.git § Heroku § cf push my-php-app -b https://github.com/cloudfoundry/php-buildpack.git § Zend § cf push my-php-app -b https://github.com/zendtech/zend-server-php-buildpack-bluemix.git § All support configuration options, but you can also fork one of these and make your own!
    32. 32. Agenda § Cloud 101 § Introducing Cloud Foundry § Demo: Simple PHP app push and MySQL bind § Services in Cloud Foundry § Buildpacks in Cloud Foundry § Demo: Scaling and zero downtime deploys § Considerations for designing PHP apps for the cloud § Demo: Cross-origin resource sharing in microservices § Where to go from here ! $ cf scale my-php-app –i 300
    33. 33. Demo 3: Scaling your PHP app up and down § cf scale meetup-cf-php-1 -i 3 (scale our app up to 3 instances) § cf app meetup-cf-php-1 (view the status of the new instances) § Load page in browser: http://meetup-cf-php-1.mybluemix.net § Reload several times and watch the hostname change (three will alternate) § cf scale meetup-cf-php-1 -i 2 (scale our app down to 2 instances) § cf app meetup-cf-php-1 (view the status of the new instances)
    34. 34. Demo 4: Zero downtime deploys § Clone meetup-cf-php-3 from https://github.com/krook/meetup-cf-php-3.git § cf push meetup-cf-php-blue § Load page in browser: http://meetup-cf-php-blue.mybluemix.net § cf apps (view the status of the one blue Version 1 instance) § cf rename meetup-cf-php-blue meetup-cf-php-green § cf apps (view the status of the one renamed green Version 1 instance) § Update code to Version 2 § cf push § cf apps (view the status of the blue instance (V2) and green instance (V1) mapped to same domain) § Reload page in browser several times to see the alternating versions: http://meetup-cf-php-blue.mybluemix.net § cf delete meetup-cf-php-green –f (delete the old green (v1) instance, routing all traffic to blue (V2)) § Reload page in browser several times to see the new version only: http://meetup-cf-php-blue.mybluemix.net !
    35. 35. Agenda § Cloud 101 § Introducing Cloud Foundry § Demo: Simple PHP app push and MySQL bind § Services in Cloud Foundry § Buildpacks in Cloud Foundry § Demo: Scaling and zero downtime deploys § Considerations for designing PHP apps for the cloud § Demo: Cross-origin resource sharing in microservices § Where to go from here !
    36. 36. Best practices for microservices architectures 12factor.net! The 12 factor app is a methodology for building apps that: • Use declarative formats for setup automation, to minimize time and cost for new developers joining the project;" • Have a clean contract with the underlying operating system, offering maximum portability between execution environments; • Are suitable for deployment on modern cloud platforms, obviating the need for servers and systems administration; • Minimize divergence between development and production, enabling continuous deployment for maximum agility; • And can scale up without significant changes to tooling, architecture, or development practices. The 12 factor methodology can be applied to apps written in any programming language, and which use any combination of backing services (database, queue, memory cache, etc).
    37. 37. Designing apps for the cloud: PaaS best practices Following these guidelines makes an application cloud-friendly, and facilitates deployment to Cloud Foundry and other cloud platforms. § Avoid writing to the local filesystem § Local file system storage is short-lived Your application can write local files while it is running, the files will disappear after the application restarts. § Instances of the same application do not share a local file system Each application instance runs in its own isolated container. Thus a file written by one instance is not visible to other instances of the same application. § HTTP sessions are not persisted or replicated Session data that must be available after an application crashes or stops, or that needs to be shared by all instances of an application, should be stored in a Cloud Foundry service. § Run multiple instances to increase availability To avoid the risk of an application being unavailable during Cloud Foundry upgrade processes, you should run more than one instance of an application. § Design as if your application can be restarted, destroyed, started at any time! http://bit.ly/cf-paas-bp !
    38. 38. Pitfall: cross-origin resource sharing (CORS) As you break monolithic apps into discrete services that are aggregated by a JavaScript front-end, you’ll likely run into an issue with the sandbox environment of the browser. Standard HTTP headers provide a way to overcome this limitation (http://bit.ly/cf-cors). http://js-front-end.example.com http://service-1.example.com http://www.example.com/service-1 http://www.example.com/service-2 http://www.example.com/service-3 http://service-2.example.com http://service-3.example.com
    39. 39. Agenda § Cloud 101 § Introducing Cloud Foundry § Demo: Simple PHP app push and MySQL bind § Services in Cloud Foundry § Buildpacks in Cloud Foundry § Demo: Scaling and zero downtime deploys § Considerations for designing PHP apps for the cloud § Demo: Cross-origin resource sharing in microservices § Where to go from here !
    40. 40. Demo 5: Breaking a monolithic app into microservices § http://krook-service-consumer.mybluemix.net § http://krook-service-provider.mybluemix.net/non-cors-provider! § http://krook-service-provider.mybluemix.net/cors-provider! !
    41. 41. More complex PHP apps on Cloud Foundry . § WordPress § http://bit.ly/cf-wp-zend § http://bit.ly/cf-wp-jstart § Symfony § http://bit.ly/cf-symfony § Laravel § http://bit.ly/cf-laravel § RESTful web services § http://bit.ly/cf-rest § Piwik § http://bit.ly/cf-piwik
    42. 42. Agenda § Cloud 101 § Introducing Cloud Foundry § Demo: Simple PHP app push and MySQL bind § Services in Cloud Foundry § Buildpacks in Cloud Foundry § Demo: Scaling and zero downtime deploys § Considerations for designing PHP apps for the cloud § Demo: Cross-origin resource sharing in microservices § Where to go from here !
    43. 43. Getting started with Cloud Foundry Basics § Trial accounts with hosted providers http://bluemix.net http://run.pivotal.io § Cloud Foundry documentation http://docs.cloudfoundry.org § Cloud Foundry community http://cloudfoundry.org § Cloud Foundry on GitHub https://github.com/cloudfoundry Advanced § “Try Cloud Foundry” on AWS https://trycf.starkandwayne.com § BOSH bootstrap https://github.com/cloudfoundry-community/bosh-bootstrap § Deploy your own to AWS http://www.slideshare.net/SpringCentral/build-yourowncf http://docs.cloudfoundry.org/deploying/ec2/ § Install on on a laptop https://github.com/cloudfoundry/bosh-lite https://github.com/yudai/cf_nise_installer § Stackato Micro Cloud http://www.activestate.com/stackato/get_stackato
    44. 44. Cloud Foundry for PHP developers! Deploy apps built with the leading open source language to the leading open source Platform-as-a-Service ‹#› Daniel Krook! Senior Certified IT Specialist, IBM" @danielkrook

    ×