如何从解压的 RPM 中使用 PHP CLI 运行 .phar 文件?

如何从解压的 RPM 中使用 PHP CLI 运行 .phar 文件?

如何重现:

  1. rpm2cpio | cpio使用名为“rpm”的目录从 CentOS 7 存储库“安装”PHP 5.4(加上 ncurses 和 OpenSSL 库)
  2. 下载phpunit.phar版本 4.8.26
  3. 跑步LD_LIBRARY_PATH=rpm/usr/lib64 rpm/usr/bin/php phpunit.phar

结果:

致命错误:在第 12 行的 […]/phpunit.phar 中找不到类“Phar”

根据官方文档 Phar 是“内置于”PHP 5.4 中的, 无论“内置于”是什么意思。确实有 arpm/usr/bin/phar和 a rpm/usr/bin/phar.phar,但我不知道如何继续rpm/usr/bin/php处理 .phar 文件。没有phar.so。没有phar根据 编译的模块LD_LIBRARY_PATH=dependencies/rpm/usr/lib64 dependencies/rpm/usr/bin/php -m | grep -i phar。尝试运行phar自身会导致混乱:

$ LD_LIBRARY_PATH=rpm/usr/lib64 rpm/usr/bin/php rpm/usr/bin/phar

Warning: stream_wrapper_register(): class 'PHP_Archive' is undefined in […]/rpm/usr/bin/phar.phar on line 6

Warning: include(): Unable to find the wrapper "phar" - did you forget to enable it when you configured PHP? in […]/rpm/usr/bin/phar.phar on line 9

Warning: include(): Unable to find the wrapper "phar" - did you forget to enable it when you configured PHP? in […]/rpm/usr/bin/phar.phar on line 9

Warning: include(phar://[…]/rpm/usr/bin/phar.phar/phar.inc): failed to open stream: No such file or directory in […]/rpm/usr/bin/phar.phar on line 9

Warning: include(): Failed opening 'phar://[…]/rpm/usr/bin/phar.phar/phar.inc' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in […]/rpm/usr/bin/phar.phar on line 9
Neither Extension Phar nor class PHP_Archive are available.

我想避免安装一整套工具(PEAR、Composer),因为这会使可移植性成为一个更大的问题。

好像没有单独的包可用于法尔。安装后epel-release唯一匹配的包pharphp-seld-phar-utils,并且似乎不包含任何相关文件:

# rpm --query --list php-seld-phar-utils
/usr/share/doc/php-seld-phar-utils-1.0.1
/usr/share/doc/php-seld-phar-utils-1.0.1/README.md
/usr/share/doc/php-seld-phar-utils-1.0.1/composer.json
/usr/share/licenses/php-seld-phar-utils-1.0.1
/usr/share/licenses/php-seld-phar-utils-1.0.1/LICENSE
/usr/share/php/Seld
/usr/share/php/Seld/PharUtils
/usr/share/php/Seld/PharUtils/Timestamps.php
/usr/share/php/Seld/PharUtils/autoload.php

相关内容