May 20, 2008

Sheraton Gateway Suite O'Hare

Talk Title Here

May 20, 2008

Sheraton Gateway Suite O'Hare

Talk Smart PHP PEAR, Phar, and Title Here

May 20, 2008

Sheraton Gateway Suite O'Hare

Talk Smart PHP PEAR, Phar, and Title Here

Gregory Beaver
PEAR president 2007-2008, PEAR/PHP developer greg.chiaraquartet.net cellog@php.net May 20, 2008 Sheraton Gateway Suite O'Hare

What is this stuff? How did you get past php| tek security?

• Lead developer of
– PEAR Installer and Pyrus – Chiara_PEAR_Server and Pyrus_SimpleChannelServer – Phar extension – PHP_Archive – PHP_ParserGenerator/PHP_LexerGenerator – phpDocumentor (inactive) – some other smaller PEAR packages

• Internal developer of PHP core • Outgoing president of PEAR • Author of The PEAR Installer Manifesto
May 20, 2008 Sheraton Gateway Suite O'Hare 2

The problem: moving stuff from here to there

• How do we move things from development to production?

May 20, 2008

Sheraton Gateway Suite O'Hare

3

The problem: moving stuff from here to there

• Internal site
– Deploying files to server – Managing web server – Dependencies – Upgrade – Revert/QA

May 20, 2008

Sheraton Gateway Suite O'Hare

4

The problem: moving stuff from here to there

• Internal site
– Deploying files to server – Managing web server – Dependencies – Upgrade – Revert/QA

• External library/app
– Packaging files together – Distributing packages – Dependencies – Upgrade/bug tracking – Managing stability/BC

May 20, 2008

Sheraton Gateway Suite O'Hare

4

The problem: moving stuff from here to there

May 20, 2008

Sheraton Gateway Suite O'Hare

5

The problem: moving stuff from here to there

• Common differences between internal and external deployment?
–Internal: More control
• No inherent need to organize files into packages

May 20, 2008

Sheraton Gateway Suite O'Hare

5

The problem: moving stuff from here to there

• Common differences between internal and external deployment?
–Internal: More control
• No inherent need to organize files into packages • Clear dependencies (PHP/OS/web)

–External: Clear QA required
• Clear upgrade path • Bug tracker

May 20, 2008

Sheraton Gateway Suite O'Hare

5

The problem: moving stuff from here to there

• Common differences between internal and external deployment?
–Internal: More control
• No inherent need to organize files into packages • Clear dependencies (PHP/OS/web)

–External: Clear QA required
• Clear upgrade path • Bug tracker • Versioning

May 20, 2008

Sheraton Gateway Suite O'Hare

5

Horror stories

What are your deployment nightmares?

May 20, 2008

Sheraton Gateway Suite O'Hare

6

How we usually approach the problem

• Internal site
– Ease of developer copying files – That’s about it

• External apps
– Deploying not my job

May 20, 2008

Sheraton Gateway Suite O'Hare

7

How we could approach the problem smarter

• Internal site
– Security – Ease of reverting changes that break things – Ease of copying files – QA integration

May 20, 2008

Sheraton Gateway Suite O'Hare

8

How we could approach the problem smarter

• Internal site
– Security – Ease of reverting changes that break things – Ease of copying files – QA integration

• External apps
– Security for remote deployment – Ease of end-user use – Ease of developer use – Managing backwards compatibility issues – Flexibility – QA integration

May 20, 2008

Sheraton Gateway Suite O'Hare

8

The solutions

May 20, 2008

Sheraton Gateway Suite O'Hare

9

The solutions

• Outside PHP

May 20, 2008

Sheraton Gateway Suite O'Hare

9

The solutions

• Outside PHP
–ftp and pray

May 20, 2008

Sheraton Gateway Suite O'Hare

9

The solutions

• Outside PHP
–ftp and pray –rsync and forget about it

May 20, 2008

Sheraton Gateway Suite O'Hare

9

The solutions

• Outside PHP
–ftp and pray –rsync and forget about it –svn switch and svn:externals

May 20, 2008

Sheraton Gateway Suite O'Hare

9

The solutions

• Outside PHP
–ftp and pray –rsync and forget about it –svn switch and svn:externals –Phing

May 20, 2008

Sheraton Gateway Suite O'Hare

9

The solutions

• Outside PHP
–ftp and pray –rsync and forget about it –svn switch and svn:externals –Phing –Capistrano

May 20, 2008

Sheraton Gateway Suite O'Hare

9

The solutions

• Outside PHP
–ftp and pray –rsync and forget about it –svn switch and svn:externals –Phing –Capistrano –Java jar

May 20, 2008

Sheraton Gateway Suite O'Hare

9

The solutions

• Outside PHP
–ftp and pray –rsync and forget about it –svn switch and svn:externals –Phing –Capistrano –Java jar –Others I’ve forgotten?

May 20, 2008

Sheraton Gateway Suite O'Hare

9

The solutions

• Inside PHP
– PEAR Installer – Phar archives – Pyrus

• Web links
– http://pear.php.net – http://php.net/phar – http://svn.pear.php.net/ PEAR2/Pyrus
Sheraton Gateway Suite O'Hare

May 20, 2008

10

The solutions: two perspectives

• End-user
– Install the installer? – Easy configuration of apps? – How easy is it to extend the installed apps or libraries?

May 20, 2008

Sheraton Gateway Suite O'Hare

11

The solutions: two perspectives

• End-user
– Install the installer? – Easy configuration of apps? – How easy is it to extend the installed apps or libraries?

• Developer
– How much will this tool distract from developing my application? – How many of my endusers will have immediate access to the tool?

May 20, 2008

Sheraton Gateway Suite O'Hare

11

PEAR Installer

May 20, 2008

Sheraton Gateway Suite O'Hare

12

PEAR Installer

• What can it do?

May 20, 2008

Sheraton Gateway Suite O'Hare

12

PEAR Installer

• What can it do?
–Pull deployment via client-server.

May 20, 2008

Sheraton Gateway Suite O'Hare

12

PEAR Installer

• What can it do?
–Pull deployment via client-server. –CLI, web and gtk installers

May 20, 2008

Sheraton Gateway Suite O'Hare

12

PEAR Installer

• What can it do?
–Pull deployment via client-server. –CLI, web and gtk installers –package.xml

May 20, 2008

Sheraton Gateway Suite O'Hare

12

PEAR Installer

• What can it do?
–Pull deployment via client-server. –CLI, web and gtk installers –package.xml –advanced dependency resolution/atuomatic download

May 20, 2008

Sheraton Gateway Suite O'Hare

12

PEAR Installer

• What can it do?
–Pull deployment via client-server. –CLI, web and gtk installers –package.xml –advanced dependency resolution/atuomatic download –Customization: file roles, tasks, install scripts

May 20, 2008

Sheraton Gateway Suite O'Hare

12

PEAR Installer: installing things

May 20, 2008

Sheraton Gateway Suite O'Hare

13

PEAR Installer: installing things

•Installation of

• pear install http://example.com/remote.tgz • pear install /path/to/local.tgz • pear install Packagename

May 20, 2008

Sheraton Gateway Suite O'Hare

13

PEAR Installer: installing things

•Installation of •Remote http-based package

• pear install http://example.com/remote.tgz • pear install /path/to/local.tgz • pear install Packagename

May 20, 2008

Sheraton Gateway Suite O'Hare

13

PEAR Installer: installing things

•Installation of •Remote http-based package •Local package

• pear install http://example.com/remote.tgz • pear install /path/to/local.tgz • pear install Packagename

May 20, 2008

Sheraton Gateway Suite O'Hare

13

PEAR Installer: installing things

•Installation of •Remote http-based package •Local package •Remote abstract package from channel server
• pear install http://example.com/remote.tgz • pear install /path/to/local.tgz • pear install Packagename

May 20, 2008

Sheraton Gateway Suite O'Hare

13

PEAR Installer: end-user perspective

May 20, 2008

Sheraton Gateway Suite O'Hare

14

PEAR Installer: end-user perspective

• Install the installer?

May 20, 2008

Sheraton Gateway Suite O'Hare

14

PEAR Installer: end-user perspective

• Install the installer?
–PEAR needs installation

May 20, 2008

Sheraton Gateway Suite O'Hare

14

PEAR Installer: end-user perspective

• Install the installer?
–PEAR needs installation –phpDocumentor – some packages work unzipand-go

May 20, 2008

Sheraton Gateway Suite O'Hare

14

PEAR Installer: end-user perspective

• Install the installer?
–PEAR needs installation –phpDocumentor – some packages work unzipand-go –Most hosts have PEAR available already –Installing PEAR:
• ./configure --with-pear

May 20, 2008

Sheraton Gateway Suite O'Hare

14

PEAR Installer: end-user perspective

• Install the installer?
–PEAR needs installation –phpDocumentor – some packages work unzipand-go –Most hosts have PEAR available already –Installing PEAR:
• ./configure --with-pear • go-pear.phar

May 20, 2008

Sheraton Gateway Suite O'Hare

14

PEAR Installer: end-user perspective

May 20, 2008

Sheraton Gateway Suite O'Hare

15

PEAR Installer: end-user perspective

• Easy configuration of apps?

May 20, 2008

Sheraton Gateway Suite O'Hare

15

PEAR Installer: end-user perspective

• Easy configuration of apps?
–Most configuration automatic through pear.conf

May 20, 2008

Sheraton Gateway Suite O'Hare

15

PEAR Installer: end-user perspective

• Easy configuration of apps?
–Most configuration automatic through pear.conf –pear run-scripts command

May 20, 2008

Sheraton Gateway Suite O'Hare

15

PEAR Installer: end-user perspective

• Easy configuration of apps?
–Most configuration automatic through pear.conf –pear run-scripts command –cfg configuration files (new in PEAR 1.7)

May 20, 2008

Sheraton Gateway Suite O'Hare

15

PEAR Installer: end-user perspective

• How easy to extend?
–Local copy possible to install
• pear config-create ~/.pearrc /home/greg/pear • pear install PEAR

–Custom file roles/tasks/install scripts

May 20, 2008

Sheraton Gateway Suite O'Hare

16

PEAR Installer: developer perspective

May 20, 2008

Sheraton Gateway Suite O'Hare

17

PEAR Installer: developer perspective

• What’s required?
–Package.xml

• What’s possible?
–Uri-based packages –Channels

May 20, 2008

Sheraton Gateway Suite O'Hare

17

PEAR Installer: developer perspective: customization

• Custom file role
–Existing roles: php, data, www, test, src, cfg –PEAR can install anything –New configuration values –Example: PEAR_Installer_Role_Chiaramdb2schema
• Marks a file as a database migration file

May 20, 2008

Sheraton Gateway Suite O'Hare

18

PEAR Installer: developer perspective: customization

• Custom tasks
–Can do anything PHP can do
• Create/update database • Modify file contents based on system configuration • Uninstall rails (oops, did I say that out loud?)

–Example: PEAR_Task_Chiara_Managedb
• Automatically create and update databases based on MDB2_Schema schema files. • Similar to Ruby migrations

May 20, 2008

Sheraton Gateway Suite O'Hare

19

PEAR Installer: developer perspective: customization

• Install scripts
– Interact with user – Simple XML format:
<file name="mysqlinstall.php" role="php"> <tasks:replace from="@php-dir@" to="php_dir" type="pear-config" /> <tasks:replace from="@data-dir@" to="data_dir" type="pear-config" /> <tasks:postinstallscript> <tasks:paramgroup> <tasks:id>questionCreate</tasks:id> <tasks:param> <tasks:name>doit</tasks:name> <tasks:prompt>Create/Upgrade database for Chiara_PEAR_Server? All previous installations must run the script</tasks:prompt> <tasks:type>string</tasks:type> <tasks:default>yes</tasks:default> </tasks:param> </tasks:paramgroup> …

May 20, 2008

Sheraton Gateway Suite O'Hare

20

PEAR Installer: developer perspective: channels

• Popular PEAR channels
–PEAR http://pear.php.net –PECL http://pecl.php.net –Symfony http://pear.symfony-project.com –Solar http://solarphp.com –eZ Components http://components.ez.no –Horde http://pear.horde.org –Seagull http://pear.phpkitchen.com –Gnope http://gnope.org/pearfront –PAT http://pear.php-tools.net
May 20, 2008 Sheraton Gateway Suite O'Hare 21

PEAR Installer: developer perspective

May 20, 2008

Sheraton Gateway Suite O'Hare

22

PEAR Installer: developer perspective

• How much will this distract me from developing my application?

May 20, 2008

Sheraton Gateway Suite O'Hare

22

PEAR Installer: developer perspective

• How much will this distract me from developing my application?
–package.xml file required for all packages

May 20, 2008

Sheraton Gateway Suite O'Hare

22

PEAR Installer: developer perspective

• How much will this distract me from developing my application?
–package.xml file required for all packages –PFM simplifies package.xml stuff –Installing a PEAR channel:
• pear channel-discover pear.chiaraquartet.net • pear install chiara/Chiara_PEAR_Server

May 20, 2008

Sheraton Gateway Suite O'Hare

22

PEAR Installer: developer perspective

• How much will this distract me from developing my application?
–package.xml file required for all packages –PFM simplifies package.xml stuff –Installing a PEAR channel:
• pear channel-discover pear.chiaraquartet.net • pear install chiara/Chiara_PEAR_Server • pear run-scripts chiara/Chiara_PEAR_Server

May 20, 2008

Sheraton Gateway Suite O'Hare

22

PEAR Installer: developer perspective

• How much will this distract me from developing my application?
–package.xml file required for all packages –PFM simplifies package.xml stuff –Installing a PEAR channel:
• pear channel-discover pear.chiaraquartet.net • pear install chiara/Chiara_PEAR_Server • pear run-scripts chiara/Chiara_PEAR_Server

–Maintaining a PEAR channel

May 20, 2008

Sheraton Gateway Suite O'Hare

22

PEAR Installer: developer perspective

• How many of my end-users will have immediate access to the tool?
–Count on 50% using PEAR (phpDocumentor download stats show this) –Installation of PEAR to get your tool could be a distraction

May 20, 2008

Sheraton Gateway Suite O'Hare

23

The future

• PHP 5.3 brings us out of old and busted…

May 20, 2008

Sheraton Gateway Suite O'Hare

24

The future

• …and into new hotness

May 20, 2008

Sheraton Gateway Suite O'Hare

25

Simple channel server

• PEAR2_SimpleChannelServer
–No database needed –REST generated directly from package tarball –Designed for smaller channels

May 20, 2008

Sheraton Gateway Suite O'Hare

26

Simple channel server (in svn now)
<?php error_reporting(E_ALL | E_NOTICE); ini_set('display_errors',true); // Get the autoloader require '/Users/bbieber/pyrus/src/PEAR2/Autoload.php'; $channel = PEAR2_SimpleChannelServer_Channel::create('ucommbieber.unl.ed u/scs','Brett Bieber\'s PEAR Channel','bieber','rest/'); $scs = new PEAR2_SimpleChannelServer($channel,'/Library/ WebServer/Documents/scs','/home/bbieber/pyrus/src'); $scs->saveChannel(); $scs->saveRelease(new PEAR2_Pyrus_Package('/Users/bbieber/ workspace/licensedtochange/LicenseSystem-0.1.0.tgz'), 'saltybeagle');

May 20, 2008

Sheraton Gateway Suite O'Hare

27

Simple channel server (namespaced)
<?php use PEAR2::Pyrus::Package; use PEAR2::SimpleChannelServer as Server; use PEAR2::SimpleChannelServer::Channel as Channel; error_reporting(E_ALL | E_NOTICE); ini_set('display_errors',true); // Get the autoloader require '/Users/bbieber/pyrus/src/PEAR2/Autoload.php'; $channel = Channel::create('ucommbieber.unl.edu/scs','Brett Bieber\'s PEAR Channel','bieber','rest/'); $scs = new Server($channel,'/Library/WebServer/Documents/scs','/home/ bbieber/pyrus/src'); $scs->saveChannel(); $scs->saveRelease(new Package('/Users/bbieber/workspace/licensedtochange/ LicenseSystem-0.1.0.tgz'), 'saltybeagle');

May 20, 2008

Sheraton Gateway Suite O'Hare

28

Phar archives: what are they?

• Phar archives are single-file applications that work without extraction:
–php blah.phar –include 'blah.phar'; –include 'phar://blah.phar/internal/file.php';

• Phar archives are tar, zip, or custom phar file format

May 20, 2008

Sheraton Gateway Suite O'Hare

29

Phar extension: end-user perspective

• How easy is it to install?
–Built into PHP 5.3+ as of last week –Available as PECL package for PHP 5.2

May 20, 2008

Sheraton Gateway Suite O'Hare

30

Phar extension: end-user perspective

• How easy is it to configure installed applications?
–Modifying contents of a phar archive could be hard for the end-user. –Mounting external configuration files is easy with Phar::mount()

May 20, 2008

Sheraton Gateway Suite O'Hare

31

Phar extension: end-user perspective

• How easy is it to extend the installed apps or libraries
–Requires specific application design to check for user configuration files –or script to directly modify the phar archive.

May 20, 2008

Sheraton Gateway Suite O'Hare

32

Phar extension: performance

May 20, 2008

Sheraton Gateway Suite O'Hare

33

Phar extension: performance

• How do pharred applications perform compared to regular file applications?

May 20, 2008

Sheraton Gateway Suite O'Hare

33

Phar extension: performance

• How do pharred applications perform compared to regular file applications?
–Without APC: currently ~1.7x slower

May 20, 2008

Sheraton Gateway Suite O'Hare

33

Phar extension: performance

• How do pharred applications perform compared to regular file applications?
–Without APC: currently ~1.7x slower –With APC: currently ~.3x slower

May 20, 2008

Sheraton Gateway Suite O'Hare

33

Phar extension: performance

• How do pharred applications perform compared to regular file applications?
–Without APC: currently ~1.7x slower –With APC: currently ~.3x slower –Serious potential for pharred applications overtaking regular application performance

May 20, 2008

Sheraton Gateway Suite O'Hare

33

Phar extension: developer perspective

• How much will this tool distract from developing my application?
–Not at all. Phar applications can be built using a simple script.
• • • • • • • <?php $phar = new Phar('app.phar.tar'); $phar->buildFromDirectory(__DIR__); $phar->setStub('<?php Phar::webPhar('app.phar.tar', 'index.php'); '); ?>

May 20, 2008

Sheraton Gateway Suite O'Hare

34

Phar extension: developer perspective

• How many of my end-users will have immediate access to this tool?
–All PHP 5.3+ users –All PHP 5.1+ users with careful design:
• Phar::setDefaultStub(), Phar::createDefaultStub() • PHP_Archive-based phar archives
–http://pear.php.net/install-pear-nozlib.phar

May 20, 2008

Sheraton Gateway Suite O'Hare

35

Phar extension: other useful features

• Data archives
–Tar (compressed tar.gz/tar.bz2 also) –Zip –Convert between formats

• Built-in web front controller
–Phar::webPhar(), Phar::mungServer()

• Solves cwd problem
–Phar::interceptFileFuncs()

May 20, 2008

Sheraton Gateway Suite O'Hare

36

Pyrus: coming soon

May 20, 2008

Sheraton Gateway Suite O'Hare

37

Pyrus: coming soon

• What is Pyrus?
– Next generation PEAR Installer – Currently in active development, working proof-of-concept in subversion

• What the hell is a pyrus?
– Pyrus is the genus of the pear fruit

May 20, 2008

Sheraton Gateway Suite O'Hare

37

Pyrus: new features in brief

• PHP 5.3+ • Run directly from pyrus.phar • Supports existing PEAR installations • Supports package.xml 2.0+ only • Supports tar, zip, and phar file formats for packages

May 20, 2008

Sheraton Gateway Suite O'Hare

38

Pyrus: new features in brief

• Deploy command • Better dependency resolution • Based on PEAR2 standards (more on this in Josh Eichorn’s talk next hour) • Easier package.xml generation • Better support for unzip-and-go applications • Basically amazing (but I’m not biased)

May 20, 2008

Sheraton Gateway Suite O'Hare

39

Questions?

• Resources:
– Documentation
• • • • • • • • • Phar docs http://php.net/phar Channels docs http://pear.php.net/manual/en/guide.migrating.channels.php Package.xml docs http://pear.php.net/manual/en/guide.developers.package2.php (commercial) PEAR Installer Manifesto http://www.packtpub.com/PEAR-Installer/book

– Software packages
PEAR Installer http://pear.php.net/PEAR PHP_Archive http://pear.php.net/PHP_Archive Phar pecl site http://pecl.php.net/phar PFM (PEAR_PackageFileManager) http://pear.php.net/PEAR_PackageFileManager Chiara_PEAR_Server http://pear.chiaraquartet.net/index.php? package=Chiara_PEAR_Server • Pyrus http://svn.pear.php.net/PEAR2/Pyrus • Pyrus_SimpleChannelServer http://svn.pear.php.net/PEAR2/sandbox/ SimpleChannelServer

– (more on next page)

May 20, 2008

Sheraton Gateway Suite O'Hare

40

It’s been fun

• Thank you! • Resources (continued)
– Other deployment strategies
• • • • • Phing http://phing.info/trac/ Capistrano http://capify.org/ Subversion http://subversion.tigris.org Java jar http://java.sun.com/docs/books/tutorial/deployment/jar/ Rsync http://samba.anu.edu.au/rsync/documentation.html

– Examples
• Custom file task example http://pear.chiaraquartet.net/index.php? package=PEAR_Task_Chiara_Managedb • Custom file role example http://pear.chiaraquartet.net/index.php? package=PEAR_Installer_Role_Chiaramdb2schema

May 20, 2008

Sheraton Gateway Suite O'Hare

41

Sign up to vote on this title
UsefulNot useful