Upgrade to Pro — share decks privately, control downloads, hide ads and more …

virtPHP: One Box, Multiple Elephpants (Day Camp for Developers: Virtualizing Development 2014)

virtPHP: One Box, Multiple Elephpants (Day Camp for Developers: Virtualizing Development 2014)

Get to the know the ins and outs of virtPHP. virtPHP is a shell tool that allows you to create multiple virtual environments for PHP applications on one system, each with unique PHP configurations, global Composer packages, PEAR packages, and PECL extensions, along with the ability to connect environments to other PHP builds located on your system. Think Python’s virtualenv for PHP.

In this talk, co-creator Ben Ramsey will introduce virtPHP and explain how it can benefit any PHP developer’s workflow. We’ll also dive into the internals of virtPHP to see how it creates self-contained virtual environments. Finally, we’ll discuss the project roadmap and how you can help.

0c217b9a7dd0aa31ed40bd0f453727e1?s=128

Ben Ramsey
PRO

August 22, 2014
Tweet

More Decks by Ben Ramsey

Other Decks in Programming

Transcript

  1. virtPHP One Box. Multiple Elephpants. @jacques_thekit @jakerella @ramsey

  2. Who am I? • Web craftsman, author, and speaker •

    Contributed array_column() to PHP • Author of rhumsaa/uuid package • User group and conference organizer • Code wrangler at ShootProof • Co-author of virtPHP
  3. Like many great coding projects, it began...

  4. ...at a hackathon.

  5. None
  6. virtualenv virtualenvwrapper

  7. virtPHP

  8. To understand virtPHP you must first understand PHP.

  9. C application

  10. C application

  11. Web Request Apache FastCGI Builtin Web Server

  12. Web Request Apache FastCGI Builtin Web Server bash

  13. bash Web Request Apache FastCGI Builtin Web Server Requester Http://

    localhost:// $
  14. None
  15. php.ini

  16. php.ini

  17. php.ini extensions C application

  18. php.ini extensions C application PECL

  19. php.ini extensions C application PECL components PHP application PEAR

  20. php.ini extensions C application PECL components PHP application PEAR

  21. php.ini extensions C application PECL Your application system application

  22. php.ini extensions C application PECL system application

  23. So, what is virtPHP?

  24. php.ini PECL PEAR system virtPHP environment

  25. php.ini PECL PEAR system virtPHP environment

  26. php.ini PECL PEAR environment1 php.ini PECL PEAR environment2

  27. php.ini PECL PEAR environment1 php.ini PECL PEAR environment2 php.ini PECL

    PEAR environment3 php.ini PECL PEAR environment4
  28. php.ini PECL PEAR environment1 php.ini PECL PEAR environment2 php.ini PECL

    PEAR environment3 php.ini PECL PEAR environment4 PHP 5.3 PHP 5.5
  29. How does virtPHP work?

  30. First, we create the project folder ../{your env}/

  31. ../{your env}/ .virtphp bin/ etc/ lib/ share/ Then, we create

    root folders
  32. ../{your env}/ .virtphp bin/ activate composer composer.phar pear peardev pecl

    php php-config phpize etc/ pear.conf php.ini … Finally, we install a lot of files … lib/ php/ share/ pear/ cache/ cfg/ download/ temp/ tests/ www/ php/
  33. ../{your env}/ .virtphp bin/ activate composer composer.phar pear peardev pecl

    php php-config phpize etc/ pear.conf php.ini … bin/ is your applications … lib/ php/ share/ pear/ cache/ cfg/ download/ temp/ tests/ www/ php/
  34. ../{your env}/ .virtphp bin/ activate composer composer.phar pear peardev pecl

    php php-config phpize etc/ pear.conf php.ini … etc/ is your configurations … lib/ php/ share/ pear/ cache/ cfg/ download/ temp/ tests/ www/ php/
  35. ../{your env}/ .virtphp bin/ activate composer composer.phar pear peardev pecl

    php php-config phpize etc/ pear.conf php.ini … lib/ is where pecl extensions go … lib/ php/ share/ pear/ cache/ cfg/ download/ temp/ tests/ www/ php/
  36. ../{your env}/ .virtphp bin/ activate composer composer.phar pear peardev pecl

    php php-config phpize etc/ pear.conf php.ini … share/pear is for pear support … lib/ php/ share/ pear/ cache/ cfg/ download/ temp/ tests/ www/ php/
  37. ../{your env}/ .virtphp bin/ activate composer composer.phar pear peardev pecl

    php php-config phpize etc/ pear.conf php.ini … share/php is for pear packages … lib/ php/ share/ pear/ cache/ cfg/ download/ temp/ tests/ www/ php/
  38. ../{your env}/ .virtphp bin/ activate composer composer.phar pear peardev pecl

    php php-config phpize etc/ pear.conf php.ini … Enlightened Pair … lib/ php/ share/ pear/ cache/ cfg/ download/ temp/ tests/ www/ php/ virtphp.phar
  39. The Keymaster

  40. ../{your env}/ .virtphp bin/ activate composer composer.phar pear peardev pecl

    php php-config phpize etc/ pear.conf php.ini … The Keymaster … lib/ php/ share/ pear/ cache/ cfg/ download/ temp/ tests/ www/ php/ virtphp.phar
  41. ../{your env}/ .virtphp bin/ activate composer composer.phar pear peardev pecl

    php php-config phpize etc/ pear.conf php.ini … The Gatekeeper … lib/ php/ share/ pear/ cache/ cfg/ download/ temp/ tests/ www/ php/
  42. The Gatekeeper

  43. activate script

  44. activate script 1. Check if a virtualenv is running

  45. activate script 2. Check if a virtPHP is running

  46. activate script 3. Deactivate any virtPHP that might be running

  47. activate script 4. Set shell session variables

  48. activate script 4. Set shell session variables • PATH •

    PS1 (prompt) • PHP_INI_SCAN_DIR • VIRTPHP_ENV_PATH • VIRTPHP_COMPOSER_GLOBAL • VIRT_PHP_OLD_VIRTUAL_PATH
  49. activate script 4. Set shell session variables Only for the

    duration of the current terminal session.
  50. Let’s see it in action.

  51. None
  52. None
  53. ramsey@virtphp:~$ wget https://github.com/virtphp/ virtphp/releases/download/v0.5.1-alpha/ virtphp.phar

  54. ramsey@virtphp:~$ wget https://github.com/virtphp/ virtphp/releases/download/v0.5.1-alpha/ virtphp.phar ! ramsey@virtphp:~$ chmod +x virtphp.phar

  55. ramsey@virtphp:~$ wget https://github.com/virtphp/ virtphp/releases/download/v0.5.1-alpha/ virtphp.phar ! ramsey@virtphp:~$ chmod +x virtphp.phar

    ! ramsey@virtphp:~$ mv virtphp.phar ~/bin/virtphp
  56. ramsey@virtphp:~$ wget https://github.com/virtphp/ virtphp/releases/download/v0.5.1-alpha/ virtphp.phar ! ramsey@virtphp:~$ chmod +x virtphp.phar

    ! ramsey@virtphp:~$ mv virtphp.phar ~/bin/virtphp ! ramsey@virtphp:~$ which virtphp /home/ramsey/bin/virtphp
  57. ramsey@virtphp:~$ wget https://github.com/virtphp/ virtphp/releases/download/v0.5.1-alpha/ virtphp.phar ! ramsey@virtphp:~$ chmod +x virtphp.phar

    ! ramsey@virtphp:~$ mv virtphp.phar ~/bin/virtphp ! ramsey@virtphp:~$ which virtphp /home/ramsey/bin/virtphp ! ramsey@virtphp:~$ virtphp
  58. None
  59. None
  60. None
  61. None
  62. ramsey@virtphp:~$ which php /usr/bin/php

  63. ramsey@virtphp:~$ which php /usr/bin/php ! ramsey@virtphp:~$ source /home/ramsey/.virtphp/ envs/project1/bin/activate

  64. ramsey@virtphp:~$ which php /usr/bin/php ! ramsey@virtphp:~$ source /home/ramsey/.virtphp/ envs/project1/bin/activate !

    (project1) ramsey@virtphp:~$
  65. ramsey@virtphp:~$ which php /usr/bin/php ! ramsey@virtphp:~$ source /home/ramsey/.virtphp/ envs/project1/bin/activate !

    (project1) ramsey@virtphp:~$ ! (project1) ramsey@virtphp:~$ which php /home/ramsey/.virtphp/envs/project1/bin/php
  66. (project1) ramsey@virtphp:~$ ! (project1) ramsey@virtphp:~$ source /home/ramsey/ .virtphp/envs/project2/bin/activate You are

    currently in a virtPHP session. Do you want to switch? y/n
  67. (project1) ramsey@virtphp:~$ deactivate ! ramsey@virtphp:~$ ! ramsey@virtphp:~$ which php /usr/bin/php

  68. ramsey@virtphp:~$ source /home/ramsey/.virtphp/ envs/project2/bin/activate

  69. ramsey@virtphp:~$ source /home/ramsey/.virtphp/ envs/project2/bin/activate ! (project2) ramsey@virtphp:~$ !

  70. ramsey@virtphp:~$ source /home/ramsey/.virtphp/ envs/project2/bin/activate ! (project2) ramsey@virtphp:~$ ! (project2) ramsey@virtphp:~$

    pecl install mongo ! ...
  71. ramsey@virtphp:~$ source /home/ramsey/.virtphp/ envs/project2/bin/activate ! (project2) ramsey@virtphp:~$ ! (project2) ramsey@virtphp:~$

    pecl install mongo ! ... ! (project2) ramsey@virtphp:~$ php --ri mongo ! mongo ! MongoDB Support => enabled Version => 1.5.5 ...
  72. (project2) ramsey@virtphp:~$ source /home/ramsey/ .virtphp/envs/project1/bin/activate You are currently in a

    virtPHP session. Do you want to switch? y/n y ! (project1) ramsey@virtphp:~$
  73. (project2) ramsey@virtphp:~$ source /home/ramsey/ .virtphp/envs/project1/bin/activate You are currently in a

    virtPHP session. Do you want to switch? y/n y ! (project1) ramsey@virtphp:~$ ! (project1) ramsey@virtphp:~$ php --ri mongo Extension 'mongo' not present.
  74. (project2) ramsey@virtphp:~$ source /home/ramsey/ .virtphp/envs/project1/bin/activate You are currently in a

    virtPHP session. Do you want to switch? y/n y ! (project1) ramsey@virtphp:~$ ! (project1) ramsey@virtphp:~$ php --ri mongo Extension 'mongo' not present. ! (project1) ramsey@virtphp:~$ pecl install mongo-1.2.12 ! ...
  75. (project2) ramsey@virtphp:~$ source /home/ramsey/ .virtphp/envs/project1/bin/activate You are currently in a

    virtPHP session. Do you want to switch? y/n y ! (project1) ramsey@virtphp:~$ ! (project1) ramsey@virtphp:~$ php --ri mongo Extension 'mongo' not present. ! (project1) ramsey@virtphp:~$ pecl install mongo-1.2.12 ! ... ! (project1) ramsey@virtphp:~$ php --ri mongo ! mongo ! MongoDB Support => enabled Version => 1.2.12
  76. None
  77. Roadmap to v1

  78. install command virtphp freeze > requirements.json virtphp install

  79. Support on Linux for: • Apache • CGI • FPM

    (potential) • phpdbg (Research for need and capability)
  80. Support on OSX for: • Apache • CGI • CLI

    • Built-in web server
  81. Support on Windows for: • IIS (maybe) • CGI •

    CLI • Built-in web server
  82. How you can help

  83. How you can help Feedback

  84. How you can help Pull requests welcomed

  85. How you can help Feature requests

  86. virtPHP Thank you. virtphp.org @virtPHP ! @jacques_thekit @jakerella @ramsey

  87. virtPHP: One Box, Multiple Elephpants Copyright © 2014 Jacques Woodcock,

    Ben Ramsey, and Jordan Kasper. Woodcock, Jacques, Ben Ramsey, and Jordan Kasper. “virtPHP: One Box, Multiple Elephpants.” Day Camp for Developers. EICC. Web conference. 22 Aug. 2014. Conference Presentation. virtPHP