简体   繁体   中英

Cannot run Phar archives

On a RHEL server I cannot seem to run PhpUnit. Here are examples as root to illustrate the steps that I've tried to install PhpUnit and how it does not run:

# wget https://phar.phpunit.de/phpunit.phar
# chmod +x phpunit.phar
# ./phpunit --version

PHP Fatal error:  require(): Failed opening required 'phar://phpunit-4.3.4.phar/phpunit/TextUI/Command.php' (include_path='.:') in /usr/local/bin/phpunit on line 592
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpunit:0
PHP   2. {closure}() /usr/local/bin/phpunit:0

# mv phpunit.phar /usr/local/bin/phpunit
# which phpunit
/usr/local/bin/phpunit

# phpunit --version

PHP Fatal error:  require(): Failed opening required 'phar://phpunit-4.3.4.phar/phpunit/TextUI/Command.php' (include_path='.:') in /usr/local/bin/phpunit on line 592
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpunit:0
PHP   2. {closure}() /usr/local/bin/phpunit:0

It seems that PHP is choking on the phar:// address format defined on line 13:

# cat /usr/local/bin/phpunit | awk 'NR==592'
          require __PHPUNIT_PHAR_ROOT__ . $classes[$class];

# cat /usr/local/bin/phpunit | grep -n __PHPUNIT_PHAR_ROOT__
13:define('__PHPUNIT_PHAR_ROOT__', 'phar://phpunit-4.3.4.phar');
592:          require __PHPUNIT_PHAR_ROOT__ . $classes[$class];
601:        print file_get_contents(__PHPUNIT_PHAR_ROOT__ . '/manifest.txt');
20811:        if (defined('__PHPUNIT_PHAR_ROOT__')) {
20812:            $prefix = __PHPUNIT_PHAR_ROOT__;
26020:        copy(__PHPUNIT_PHAR_ROOT__ . '/ca.pem', $caFile);

The server is RHEL 6.5:

# uname -a
Linux foobar 2.6.32-220.38.1.el6.x86_64 #1 SMP Wed May 15 08:34:56 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/issue
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Kernel \r on an \m

The solution was to just use PHPUnit from PEAR, which also would not run with this error:

[root@panthercrm ~]# /usr/bin/phpunit
PHP Warning:  require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /usr/share/pear/PHPUnit/
Autoload.php on line 64
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. require() /usr/bin/phpunit:43
PHP Fatal error:  require_once(): Failed opening required 'File/Iterator/Autoload.php' (include_path='.:') in /usr/share/pear/PHPUni
t/Autoload.php on line 64
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. require() /usr/bin/phpunit:43        

Adding the following line to /etc/php.ini resolved the issue for the PEAR version of PHPUnit:

include_path = ".:/usr/share/pear"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM