phpunit安裝出錯的原因及解決方案

來源:互聯網
上載者:User
phpunit安裝出錯的原因及解決辦法

官方指引

很遺憾, phpunit還沒有在ArchLinux的倉庫裡。

所以使用下載安裝的方式。按照官方的指引:

wget https://phar.phpunit.de/phpunit.pharchmod +x phpunit.pharsudo mv phpunit.phar /usr/local/bin/phpunitphpunit --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 Fatal error:  Class 'Phar' not found in /usr/local/bin/phpunit on line 714

啟用phar擴充

先解決Fatal error: Class 'Phar' not found

ls /usr/lib/php/modules

發現有 phar.so,說明Phar的擴充已經安裝,那麼是不是該擴充沒有Enable呢?
開啟 /etc/php/php.ini搜尋 phar,果然發現 extension=phar.so被注釋掉了。去掉該行前面的 ;,儲存php.ini,再次運行 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 error解決了,但警告還在,而且phpunit沒有正常運行。

php對檔案訪問的保護機制

google之,發現這裡有解釋: 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: ...

意思是說:php.ini中的open_basedir是php為保證安全進行檔案訪問的設定。如果該選項被賦值,所有的檔案操作將限定在特定的目錄裡,這樣可以防止某個使用者使用php指令碼讀取未授權的內容。當你想通過fopengzopen開啟一個檔案時,如果該檔案的位置不再被允許的目錄下面,就會出現上述的警告資訊。

從警告資訊發現可以訪問的目錄包括 /srv/http/:/home/:/tmp/:/usr/share/pear/,剛好 ~/bin即在PATH變數中,也屬於可以被php指令碼讀取的目錄,於是

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

再運行phpunit --version,得到正確結果:

PHPUnit 4.5.0 by Sebastian Bergmann and contributors.

phpunit安裝成功!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.