Saucelabs
Saucelabs
Back to Resources

Blog

Posted April 27, 2011

How to serve PHP/Pear packages with GitHub

quote

PHP packages are distributed through Pear channels. If you want to download a PHP package, it’s as simple as downloading Pear and using it. The process of using pear is telling it the "channel" you want to download the package from, and then telling it to download the package. That's what you do if you want to download somebody else's PHP. If you want other people to be able to download yours, you have to make your own pear channel. We had to do that recently, and it turns out there’s an easy way to do it thanks to GitHub and Fabien Potencier's Pirum. It’s pretty straightforward. Here come the lists. So many lists! Like 40. Still. Straightforward. By the way, you'll need to install pear and install git if you haven't already.


Make a pear channel

  1. Create a new repository on GitHub called pear

    1. Make the project on github

    2. $ mkdir pear

    3. $ cd pear

    4. $ git init

    5. $ git remote add origin git@github.com:[your git username]/pear.git

  2. Install Pirum

    1. $ pear channel-discover pear.pirum-project.org

    2. $ pear install pirum/Pirum-beta

  3. Create a pirum configuration file:

    1. It's called pirum.xml

    2. It goes in the root of your pear repository

    3. It contains:

      1. <?xml version="1.0" encoding="UTF-8" ?> <server> <name>[username].github.com/pear</name> <summary>[username]'s PEAR Channel Server</summary> <alias>[username]</alias> <url>http://[username].github.com/pear</url> </server>

  4. Run the build command

    1. $ pirum build .

  5. Now add and commit everything

    1. $ git add -A

    2. $ git commit -m "Initial server build. Sauce Labs is awesome"

  6. Rename your master branch to gh-pages and push it to GitHub

    1. $ git branch -m master gh-pages

    2. $ git push origin gh-pages

  7. Your PEAR channel server is now available (after maybe 15 minutes) under [username].github.com/pear. Test it out!

    1. $ pear channel-discover [username].github.com/pear

    2. $ pear channel-info [username]

    3. $ pear list-all -c [username]


There! Now you have a pear channel. Now you need to

Make a PHP package

  1. Go to the directory that contains your PHP files

  2. Create a package.xml file that contains metadata about your package

  3. Check that it's a valid package

    1. $ pear package-validate

  4. Make the package!

    1. $ pear package (this should create a .tgz file that's named after the package you detailed in package.xml)


Woo! Now you have a package and a channel. Next step is to  

Add the package to the channel

  1. Copy the .tgz file to your pear repository

  2. Navigate to that directory

  3. Add the package to the channel locally

    1. $ pirum add . [filename].tgz

  4. Upload the changes to github! Note that you push to gh-pages and not to master.

    1. $ git add -A

    2. $ git commit -m "Added first version of my pear package. Sauce Labs is awesome"

    3. $ git push origin gh-pages


And you're done! No more bullets! Or numbered lists. Now the whole world is exposed to your PHP. Hopefully that's a good thing.   Here’s our Pear channel: https://github.com/saucelabs/pear Here’s the source we distribute through it: https://github.com/saucelabs/phpunit-selenium-sauceondemand Special thanks to Jan Sorgalla for showing me by example how to do all this.

Published:
Apr 27, 2011
Topics
Share this post
Copy Share Link
© 2023 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.