Creating your own PEAR channel using GitHub
Autor: Gabriel Ricci | Publicado: 2011-12-07T19:19:00-02:00

  Every PHP developer always dreamed about having his own PEAR channel, in this post I'll show you guys how to create it. Lets begin by understanding how does PEAR work, basically, a PEAR channel is a REST service with all the needed information about the packages on the channel, such as releases, stability, maintainers, categories and stuff. If you use this channel, the PEAR client will hit this "service" and parse all the information about the packages.  The last and final step is the installation of the package itself, the PEAR client hits the channel, parses the information about the last release of the package, download it and extract the files in the include path, nothing more, nothing less, it's that ease.  So the first step is create the channel is to set up GitHub, let's create a repository called "pear"      Create the repository on GitHub  $ mkdir pear  $ cd &nbsp;pear  $ git init  $ touch README  $ git add README  $ git commit -m 'First commit'  $ git remote add origin git@github.com:[your git username]/pear.git  $ git push -u origin master&nbsp;    Now we must active the gh-pages branch on our new repository. In every repository, if you create a branch called&nbsp;gh-pages, all the files on that branch will be available on the URL http://[your git username].github.com/[you repository name], and GitHub is transformed in a webserver.    $ cd pear  $ git symbolic-ref HEAD refs/heads/gh-pages  $ rm .git/index  $&nbsp;git clean -fdx    Now, the next step is create the files that compose the PEAR channel/server structure, and as you can imagine, this is a very painfull (and boring) task, but in order to make things easier, we'll use Pirum, a PEAR package that automatically create all the needed files, and since Pirum is a PEAR package, we'll install it using...PEAR.    $ pear channel-discover pear.pirum-project.org  $ pear install pirum/Pirum    With Pirum installed, we just need to create one more file, called pirum.xml, this file contains the basic information that Pirum need in order to create the channel structure, it must be created inside the pear folder and must be as follows:  &lt;?xml version="1.0" encoding="UTF-8" ?&gt;&lt;server&gt;&nbsp; &lt;name&gt;[your github user].github.com/pear&lt;/name&gt;&nbsp; &lt;summary&gt;[your github user] PEAR channel&lt;/summary&gt;&nbsp; &lt;alias&gt;[your github user]&lt;/alias&gt;&nbsp; &lt;url&gt;http://[your github user].github.com/pear&lt;/url&gt;&lt;/server&gt;  Change the file to meet your informations and save it, and with&nbsp;the file created, you are ready to create the channel.    $ cd pear  $ pirum build .&nbsp;  $ git add -A  $ git commit -m "Channel created"  $ git push origin gh-pages    Your PEAR channel is now available (but in some cases GitHub can take up to 10 minutes to activate GitHub Pages on your acount), and you can test it out.    $ pear channel-discover [your github user].github.com/pear  $ pear channel-info [your github user]    Now that you have your channel, you probably want to add some packages to it, and to make this you need to create a package.xml file for each project that you want to create a package, this file can be huge, mostly by the fact that every file in your project must be listed in the package.xml file, so create the package.xml file manually can be even more painfull than the creation of the channel itself, so again, in order to make things easier, we'll use another software, Pearfarm.  Pearfarm reads all the files in your project and create the package.xml file based on a specification file. But, enough talking, let's start.    $ pear channel-discover pearfarm.pearfarm.org  $ pear install pearfarm.pearfarm.org/pearfarm  Go to the directory that contains your project files (not the pear directory)  $ pearfarm build  After you run the above command, a file named pearfarm.spec will be created on the directory that contains your project files, open this file and edit the information about your project  $ pearfarm build    At this point, you are ready to create your package, let's validate the package.xml file generated by Pearfarm and then build our package (at this point, you can also make manual changes on the package.xml file that Pearfarm has generated if you need, but be carefull).    $ pear package-validate  $ pear package&nbsp;    Package created, now lets add it to your channel.    Copy the .tgz file to your pear directory  $ cd pear&nbsp;  $ pirum add . [filename].tgz&nbsp;  $ pirum build .&nbsp;  $ git add -A  $ git commit -m "My first package added to my channel, thanks Gabriel Ricci"  $ git push origin gh-pages    And you're done, now everyone can have access to your projects through PEAR, don't forget to take a look at my PEAR channels, http://gabrielricci.github.com/pear and http://terophp.github.com/pear and at my repositories in GitHub, http://www.github.com/gabrielricci and http://www.github.com/TeroPHP.  Oh, one last thing, in my experience PEAR is not the most easy application to deal with, it has it's own cache system which may drive you crazy, so, http://pear.php.net and Google are your friends.