Search code examples
phpcomposer-phppear

Have Composer auto-load PEAR's code (e.g. PEAR.php) for archive_tar from within vendor directory?


I have a development machine with PEAR installed on it (in /usr/share/php/PEAR.php) and a production system without PEAR installed on it.

On the production box, I get this error that I don't get on the dev machine:

A PHP Error was encountered
Severity: Warning
Message: require_once(PEAR.php): failed to open stream: No such file or directory
Filename: Archive/Tar.php
Line Number: 42
Fatal error: require_once(): Failed opening required 'PEAR.php' (include_path='.:') in /www/application/vendor/pear/archive_tar/Archive/Tar.php on line 42

See line 42 here: https://github.com/pear/Archive_Tar/blob/master/Archive/Tar.php#L42

I don't want to install PEAR on the production box because it's installed system wide. It seems much cleaner to me if I can install PEAR.php and all its associated files from composer itself.

All the questions relating to Composer and PEAR that I can find are related to installing the package from Composer.

But what I want to do is have Composer auto-load the PEAR code from within the project's vendor directory so that I don't have to globally install PEAR on the production system.

There's a practically identical question here: How do I get PEAR.php with Composer?

But it looks like he's accepted his own answer which didn't even fix the problem.

My composer.json looks like:

{
    "require": {
        "pear/archive_tar": "*",
    }
}

It seems like, if what I propose is possible, I would add "pear/pear" or something to require and it would install the PEAR code itself in the project directory, but I can't find such a package.


Solution

  • Eventually found a Github gist where someone listed "pear-pear/PEAR" as the package you need:

    }
        "repositories": [
            {
                "type": "pear",
                "url": "http://pear.php.net"
            }
        ],
        "require": {
            "pear-pear/PEAR": "*",
            "pear/archive_tar": "*"
        }
    }