Home  >  Article  >  Backend Development  >  Reasons and solutions for phpunit installation errors

Reasons and solutions for phpunit installation errors

WBOY
WBOYOriginal
2016-08-08 09:29:501277browse

Official Guidelines

Unfortunately, phpunit is not yet in the ArchLinux repository.

So use the download and installation method. Follow official guidelines:

<code>wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit
phpunit --version</code>

The result is the following error:

<code>PHP Warning:  realpath(): open_basedir restriction in effect. File(/usr/local/bin/phpunit) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) in /usr/local/bin/phpunit on line 3
PHP Fatal error:  Class 'Phar' not found in /usr/local/bin/phpunit on line 714</code>

Enable phar extension

First solveFatal error: Class 'Phar' not found.

<code>ls /usr/lib/php/modules</code>

Found phar.so, which means that the Phar extension has been installed. So is the extension not Enabled?
Open /etc/php/php.iniSearch for phar, and sure enough, we found that extension=phar.so was commented out. Remove the ; in front of the line, save php.ini, and run phpunit --version again.

<code>PHP Warning:  realpath(): open_basedir restriction in effect. File(/usr/local/bin/phpunit) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) in /usr/local/bin/phpunit on line 3
PHP Warning:  Phar::mapPhar(): open_basedir restriction in effect. File(/usr/local/bin/phpunit) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) in /usr/local/bin/phpunit on line 714</code>

Fatal error is resolved, but the warning is still there and phpunit is not running properly.

php protection mechanism for file access

Google and found an explanation here: http://www.templatemonster.com/help/open_basedir-restriction-in-effect-filex-is-not-within-the-allowed-paths-y.html

PHP open_basedir protection tweak is a Safe Mode security measure that prevents users from opening files or scripts located outside of their home directory with PHP, unless the folder has specifically excluded. PHP open_basedir setting if enabled, will ensure that all file operations to be limited to files under certain directory, and thus prevent php scripts for a particular user from accessing files in unauthorized user's account. When a script tries to open a file with, for example, fopen() or gzopen(), the location of the file is checked. When the file is outside the specified or permissible directory-tree, PHP will refuse to open it and the following errors may occur: ...

It means: open_basedir in php.ini is a setting of PHP to ensure safe file access. If this option is assigned, all file operations will be limited to specific directories, which prevents a user from using PHP scripts to read unauthorized content. When you want to open a file through fopen or gzopen, if the file is located in a directory that is no longer allowed, the above warning message will appear.

From the warning message, we found that the accessible directories include /srv/http/:/home/:/tmp/:/usr/share/pear/. It happens that ~/bin is in the PATH variable and can also be accessed. The directory read by the php script, so

<code>mv /usr/local/bin/phpunit ~/bin</code>

Run phpunit --version again to get the correct result:

<code>PHPUnit 4.5.0 by Sebastian Bergmann and contributors.</code>

phpunit installed successfully!

The above introduces the causes and solutions of phpunit installation errors, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php-singly linked listNext article:php-singly linked list