Nick Jones

a magento developer at Meanbee (@nickj89) and uk magento expert based in Bath

Manually Building Magento PEAR Packages

The internal Magento package builder is all very well and good for getting your basic package.xml generated, and defining your file lists, but it is cumbersome to use and can’t be integrated into a build process very easily.

Magento extends the PEAR tool to provide a mp (make package) function which replaces the package and package-validate commands. Here’s how to build your package.

You’ll notice that I refer to the pear program as ./pear throughout this article. This is because we’re using Magento’s version, with the Magento Team’s modifications applied. The ./pear is found in the root of your Magento installation.

Generating your package.xml

The first time around I like to use the Magento package builder in the Magento admin area. You’ll find this in System » Magento Connect » Package Extensions. Once you’re done you can hit Save save your settings for this package for the next time you want to build from this interface, making all of the fields populate from the Load local Package menu item.

The fields will be saved as ${your_package_name}.xml in the $MAGE_ROOT/var/pear/ directory.

To generate your package.xml you’ll need to hit the Save data and Create Package button. The package.xml can be found in $MAGE_ROOT/var/pear/ also.

Building your Package

This is the easy step. Simply navigate to the root of your Magento installation, copy the package.xml there and run pear, like so:

cp var/pear/package.xml .
./pear mp package.xml

You’ll then get a success message and your package is ready to roll.

Installing your Package

If you don’t have a PEAR server setup then you can install the package by simply specifying the file name when calling ./pear install, as follows:

./pear install My_Package-0.9.0.tgz

Potential Pitfalls

  1. ./pear mp package.xml does not generate a valid tgz archive.

    I wasn’t getting any errors during package creation, but once I had uploaded to my PEAR server and attempted to install I was getting these funky messages.

    [nrj@clifford heirloom]$ ./pear install -f meanbee/My_Package
    downloading My_Package-0.9.0.tgz ...
    Starting to download My_Package-0.9.0.tgz (2,132,243 bytes)
    ....................................................................................................................................................................................................................................................................................................................................................................................................................................done: 2,132,243 bytes
    Could not get contents of package "/magento/root/downloader/pearlib/download/My_Package-0.9.0.tgz". Invalid tgz file.
    Download of "meanbee/My_Package" succeeded, but it is not a valid package archive
    Error: cannot download "meanbee/My_Package"
    Download failed
    install failed
    

    I tested the archive that was created by simply untaring which produced various complaints about base64 headers and there was a lot of Skipping to next header.

    This is a bug with the Archive_Tar package hosted at the official PEAR Repository. There is already a working patch submitted, but it has not yet made it’s way into any release. We can apply the patch manually by downloading the patch and patching the Tar.php file in downloader/pearlib/php/Archive/ by running:

    patch Tar.php downloaded.patch

One Response to Manually Building Magento PEAR Packages

  1. Håkon says:

    Is it possible to upload a Tar.php file which is already patched? Im having difficulty understandig how to patch the two files together.

    Regards
    Håkon

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">