PHPUnit installation error causes and solutions

Source: Internet
Author: User
Tags pear php tutorial
Official guidelines

Unfortunately, PHPUnit is not yet in ArchLinux's warehouse.

So use the download installation method. According to the official guidelines:

wget https://phar.phpunit.de/phpunit.pharchmod +x phpunit.pharsudo mv phpunit.phar /usr/local/bin/phpunitphpunit --version

The result gets the following error:

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 3PHP Fatal error:  Class 'Phar' not found in /usr/local/bin/phpunit on line 714

Enable Phar Extension

Resolved first Fatal error: Class 'Phar' not found .

ls /usr/lib/php/modules

Found that there is a phar.so, indicating that the Phar extension has been installed, then the extension is not enable it?
Open /etc/php/php.ini phar The search, and sure enough, extension=phar.so it was commented out. Remove the front of the line ; , save PHP.ini, and run again phpunit --version .

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 3PHP 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

Fatal errorResolved, but the warning is still in, and phpunit is not functioning properly.

The protection mechanism of PHP for file access

Google's, found here to explain: 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 This prevents users from opening files or scripts locate D outside of their home directory with PHP, unless the folder has specifically excluded. PHP open_basedir Setting if enabled, would ensure that all file operations to is limited to files under certain directory, And thus prevent PHP scripts for a particular the 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 would refuse to open it and the following errors May occur: ...

This means that php.ini open_basedir is the setting for secure file access in PHP. If this option is assigned, all file operations are scoped to a specific directory, which prevents a user from using PHP scripts to read unauthorized content. When you want to pass fopen or gzopen open a file, the above warning message appears if the location of the file is no longer allowed under the directory.

The list of directories accessible from the warning message is included /srv/http/:/home/:/tmp/:/usr/share/pear/ , just as ~/bin in the path variable, which is also a directory that can be read by a PHP script, so

mv /usr/local/bin/phpunit ~/bin

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

PHPUnit 4.5.0 by Sebastian Bergmann and contributors.

PHPUnit installation is successful!

The above describes the PHPUnit installation error reasons and solutions, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.