Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Using PHPwith IBM Bluemix
Vikram Vaswani
August 2017
Vikram Vaswani
Founder, Melonfire
● Product design and implementation with open source
technologies
● 20+ productslaunched...
Vikram Vaswani
ActiveIBM Bluemix user since2014
● IBM Cloud Champion
● 15+ PHPapplicationson IBM Bluemix
● Stray assist: h...
Bluemix
● Cloud PaaS
● Secureand scalable
● Pay-per-use
● Multipleprogramming languages
● PHP, Java, Go, Ruby, Swift, ...
...
Bluemix
● Serverlesscomputing
● ApacheOpenWhisk
● Integrated continuousdelivery toolchains
● Own and externally-hosted rep...
Bluemix and PHP
● PHPruntimeviaCloud Foundry PHPbuildpack
● Key features
● Choiceof Web servers: Apacheor nginx
● Choiceof...
Development Approaches
UsethePHPstarter application asbase
● Deploy thestarter application to Bluemix
● Download thesource...
Development Approaches
Start from scratch
● Develop theapplication locally
● Incorporatelocal or remoteservices
● Deploy t...
Development Steps
1.Defineand install application dependencies
2.Configureapplication with local servicecredentials
3.Find...
Deployment Steps
1.Find and instantiateremoteservices
2.Updateapplication to retrieveremoteservice
credentialsfrom Bluemix...
Development
Development: Prerequisites
● Bluemix account
● Third-party serviceaccounts(if needed)
● Local PHPdevelopment environment
●...
Development: Dependencies
● Useco mpo ser.jso n to
● Specify thePHPversion
● Declaredependenciesand version constraints
● ...
Development: Dependencies
Sampleco mpo ser.jso n file:
{
"require": {
"php": ">=7.0.0",
"slim/slim": "^3.8",
"slim/php-vie...
Development: ServiceDiscovery
Find servicesusing theBluemix Dashboard
● 120+ services, IBM and third-party
● Many services...
Development: ServiceInstantiation
Instantiatenew servicesusing theBluemix Dashboard
● Leaveservicesunbound for local devel...
Deployment
Pre-Deployment: ServiceCredentials
● Availablein Bluemix environment for all bound services
viaVCAP_ SERVICES variable
● S...
Pre-Deployment: ServiceCredentials
Samplecode:
<?php
// if BlueMix VCAP_SERVICES environment available
// overwrite local ...
Deployment: ConfigurationArtifacts
● Application manifest (manifest.yml)
● Buildpack configuration data(.bp-co nfig/* )
Deployment: Application Manifest
Usemanifest.yml to defineapplication attributes:
● Host name
● Application name
● Memory
...
Deployment: Application Manifest
Samplemanifest.yml file:
---
applications:
- name: myapp-[initials]
memory: 256M
instance...
Deployment: Buildpack Configuration
● Use.bp-co nfig/o ptio ns.jso n to:
● ConfiguretheWeb server and document root
● Set ...
Deployment: Buildpack Configuration
Sample.bp-co nfig/o ptio ns.jso n file:
{
"WEB_SERVER": "httpd",
"COMPOSER_VENDOR_DIR"...
Deployment: Buildpack Configuration
Sample.bp-co nfig/php/php.ini.d/php.ini file:
extension=mysqli.so
default_charset="UTF...
Deployment: CodePush
● Set API endpoint
cf api ENDPOINT
● Log in
cf login
● Push application
cf push
Deployment: CodePush Results
When aPHPapplication ispushed:
● Theapplication metadataisstored and arouteand record iscreat...
Deployment: ServiceBinding
● Bind services:
cf bind-service APP-NAME SERVICE-
NAME
● Set custom environment variables:
cf ...
Post-Deployment: Debugging
● View logs:
cf logs APP-NAME
cf logs APP-NAME --recent
● Start secureshell session:
cf ssh APP...
ContinuousDelivery
ServiceOverview
● Secure, automated, repeatablebuild/deployment
processes
● Integrated toolchains
● Bluemix services
● Thi...
ServiceFeatures
● Toolchain templates
● Pipelines
● Web IDE
● Hosted repository
● Custom scripting
Learn moreat http://vik...
Example
Tests
pass?
New
PR
Approve
and
merge PR
Reject
and
return PR
Pull and
build code
Deploy
code
Source code repositor...
Demonstration
Demonstration Overview
● Cloneapplication sourcecode
● Configurewith local development MySQL database
● CreateClearDB Mana...
SampleApplication
● PHP+MySQL application using Slim micro-
framework
● UsesBluemix ClearDB Managed MySQL service
● Usescu...
Questions?
Contact Information
Email:
● vikram-vaswani.in/contact
Web:
● www.melonfire.com
● vikram-vaswani.in
Social networks:
● plu...
Upcoming SlideShare
Loading in …5
×

Using PHP with IBM Bluemix

440 views

Published on

Discusses the steps involved in developing and deploying a PHP application on IBM Bluemix.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Using PHP with IBM Bluemix

  1. 1. Using PHPwith IBM Bluemix Vikram Vaswani August 2017
  2. 2. Vikram Vaswani Founder, Melonfire ● Product design and implementation with open source technologies ● 20+ productslaunched for customersworldwide Author and activePHPcommunity participant ● 7 booksfor McGraw-Hill USA ● 250+ tutorialsfor IBM dW, Zend Developer Zoneand others Moreinformation at http://vikram-vaswani.in
  3. 3. Vikram Vaswani ActiveIBM Bluemix user since2014 ● IBM Cloud Champion ● 15+ PHPapplicationson IBM Bluemix ● Stray assist: http://stray-assist.mybluemix.net/ ● Invoicegenerator: https://invoice-generator.mybluemix.net/ ● ATM finder: http://atm-finder.mybluemix.net/ ● Document indexer: https://pdf-keyword-search.mybluemix.net Codesamplesat https://github.com/vvaswani
  4. 4. Bluemix ● Cloud PaaS ● Secureand scalable ● Pay-per-use ● Multipleprogramming languages ● PHP, Java, Go, Ruby, Swift, ... ● Multipleservices(own and third-party) ● Text to Speech, Object Storage, Spark, Sendgrid, ...
  5. 5. Bluemix ● Serverlesscomputing ● ApacheOpenWhisk ● Integrated continuousdelivery toolchains ● Own and externally-hosted repositories ● Web IDE ● Third-party integrations: Slack, GitHub ● Blue-green deployment and rollback
  6. 6. Bluemix and PHP ● PHPruntimeviaCloud Foundry PHPbuildpack ● Key features ● Choiceof Web servers: Apacheor nginx ● Choiceof PHPversions: PHP5 or PHP7 ● Support for variousPHPextensionsand modules ● Support for Composer and custom startup scripts ● Debug logs PHPbuildpack docsat http://docs.cloudfoundry.org/buildpacks/php/
  7. 7. Development Approaches UsethePHPstarter application asbase ● Deploy thestarter application to Bluemix ● Download thesourcecodeand modify locally ● Incorporatelocal or remoteservices ● Redeploy thefinal application to Bluemix and bind servicesasneeded Benefits ● Simple, easy to understand ● Best for first-timeusers
  8. 8. Development Approaches Start from scratch ● Develop theapplication locally ● Incorporatelocal or remoteservices ● Deploy thefinal application to Bluemix and bind servicesasneeded Benefits ● Greater flexibility and customization options ● Best for experienced developers
  9. 9. Development Steps 1.Defineand install application dependencies 2.Configureapplication with local servicecredentials 3.Find and instantiateany remoteservicesneeded for development 4.Configureapplication with remoteservice credentials 5.Develop, test and finalize
  10. 10. Deployment Steps 1.Find and instantiateremoteservices 2.Updateapplication to retrieveremoteservice credentialsfrom Bluemix 3.Defineapplication manifest 4.Push application 5.Bind remoteservices 6.Test application
  11. 11. Development
  12. 12. Development: Prerequisites ● Bluemix account ● Third-party serviceaccounts(if needed) ● Local PHPdevelopment environment ● CloudFoundry CLI ● Application sourcecode(obviously!) CloudFoundry CLI installation instructionsat https://docs.cloudfoundry.org/cf-cli/install-go-cli.html
  13. 13. Development: Dependencies ● Useco mpo ser.jso n to ● Specify thePHPversion ● Declaredependenciesand version constraints ● Useco mpo ser.lo ck to ● Lock your application to specific versionsof dependencies
  14. 14. Development: Dependencies Sampleco mpo ser.jso n file: { "require": { "php": ">=7.0.0", "slim/slim": "^3.8", "slim/php-view": "^2.2" } }
  15. 15. Development: ServiceDiscovery Find servicesusing theBluemix Dashboard ● 120+ services, IBM and third-party ● Many servicesincludeafreetier
  16. 16. Development: ServiceInstantiation Instantiatenew servicesusing theBluemix Dashboard ● Leaveservicesunbound for local development ● Obtain credentialsfrom each servicepanel
  17. 17. Deployment
  18. 18. Pre-Deployment: ServiceCredentials ● Availablein Bluemix environment for all bound services viaVCAP_ SERVICES variable ● Structured asJSON document
  19. 19. Pre-Deployment: ServiceCredentials Samplecode: <?php // if BlueMix VCAP_SERVICES environment available // overwrite local credentials with BlueMix credentials if ($services = getenv("VCAP_SERVICES")) { $json = json_decode($services, true); $config['db']['hostname'] = $json['cleardb'][0]['credentials']['hostname']; $onfig['db']['username'] = $json['cleardb'][0]['credentials']['username']; $config['db']['password'] = $json['cleardb'][0]['credentials']['password']; $config['db']['name'] = $json['cleardb'][0]['credentials']['name']; }
  20. 20. Deployment: ConfigurationArtifacts ● Application manifest (manifest.yml) ● Buildpack configuration data(.bp-co nfig/* )
  21. 21. Deployment: Application Manifest Usemanifest.yml to defineapplication attributes: ● Host name ● Application name ● Memory ● Number of instances ● Buildpack
  22. 22. Deployment: Application Manifest Samplemanifest.yml file: --- applications: - name: myapp-[initials] memory: 256M instances: 1 host: myapp-[initials] buildpack: https://github.com/cloudfoundry/php-buildpack.git stack: cflinuxfs2
  23. 23. Deployment: Buildpack Configuration ● Use.bp-co nfig/o ptio ns.jso n to: ● ConfiguretheWeb server and document root ● Set thePHPversion (if conflict, co mpo ser.jso n getspriority) ● EnablePHPmodulesand Zend extensions ● Use.bp-co nfig/php/php.ini.d/*.ini to: ● ConfigurePHPsettings ● EnablePHPextensions ● Use.bp-co nfig/httpd/httpd.co nf to: ● ConfigureApachesettings
  24. 24. Deployment: Buildpack Configuration Sample.bp-co nfig/o ptio ns.jso n file: { "WEB_SERVER": "httpd", "COMPOSER_VENDOR_DIR": "vendor", "WEBDIR": "public", "PHP_VERSION": "{PHP_70_LATEST}" }
  25. 25. Deployment: Buildpack Configuration Sample.bp-co nfig/php/php.ini.d/php.ini file: extension=mysqli.so default_charset="UTF-8" display_errors="1" display_startup_errors="1" error_reporting="E_ALL" List of PHPbuildpack extensionsenabled by default at https://github.com/cloudfoundry/php-buildpack/releases/
  26. 26. Deployment: CodePush ● Set API endpoint cf api ENDPOINT ● Log in cf login ● Push application cf push
  27. 27. Deployment: CodePush Results When aPHPapplication ispushed: ● Theapplication metadataisstored and arouteand record iscreated for it. ● Theapplication assetsareuploaded. ● ThePHPbuildpack isdownloaded and executed. ● ThePHPbuildpack downloadsand configurestheWeb server and PHPbinary. ● ThePHPbuildpack usesComposer to install application dependencies. ● Thestaged PHPapplication ispackaged into a"droplet". ● Thedroplet isuploaded and thestaged PHPapplication isstarted. Moreinformation at https://docs.cloudfoundry.org/concepts/how- applications-are-staged.html
  28. 28. Deployment: ServiceBinding ● Bind services: cf bind-service APP-NAME SERVICE- NAME ● Set custom environment variables: cf set-env APP-NAME VARIABLE VALUE ● Restageapplication: cf restage APP-NAME
  29. 29. Post-Deployment: Debugging ● View logs: cf logs APP-NAME cf logs APP-NAME --recent ● Start secureshell session: cf ssh APP-NAME Learn moreat http://vikram- vaswani.in/weblog/2015/03/19/debugging-php-errors- on-ibm-bluemix/
  30. 30. ContinuousDelivery
  31. 31. ServiceOverview ● Secure, automated, repeatablebuild/deployment processes ● Integrated toolchains ● Bluemix services ● Third-party tools – Slack – GitHub – SauceLabs – PagerDuty
  32. 32. ServiceFeatures ● Toolchain templates ● Pipelines ● Web IDE ● Hosted repository ● Custom scripting Learn moreat http://vikram- vaswani.in/weblog/2017/08/22/test-and-deploy-php- applications-automatically-on-ibm-bluemix/
  33. 33. Example Tests pass? New PR Approve and merge PR Reject and return PR Pull and build code Deploy code Source code repository dev-master branch Bluemix environment dev-master.mybluemix.net Perform custom actions Bluemix webhook Bluemix continuous delivery service Y N
  34. 34. Demonstration
  35. 35. Demonstration Overview ● Cloneapplication sourcecode ● Configurewith local development MySQL database ● CreateClearDB Managed MySQL Databaseserviceon Bluemix ● Updateapplication codeto useservicecredentialsin Bluemix environment ● Createapplication manifest ● ConfigureCloud Foundry PHPbuildpack ● Deploy application to Bluemix ● Bind ClearDB Managed MySQL Databaseserviceto application ● Test and debug deployment ● Implement continuousdelivery toolchain
  36. 36. SampleApplication ● PHP+MySQL application using Slim micro- framework ● UsesBluemix ClearDB Managed MySQL service ● Usescustomized buildpack configuration Codeat https://github.com/vvaswani/bluemix-cities
  37. 37. Questions?
  38. 38. Contact Information Email: ● vikram-vaswani.in/contact Web: ● www.melonfire.com ● vikram-vaswani.in Social networks: ● plus.google.com/100028886433648406825 MySQL/PHPuser group: ● https://plus.google.com/+mmpugindia/

×