官方指引

很遗憾, phpunit还没有在ArchLinux的仓库里。

所以使用下载安装的方式。按照官方的指引

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit
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 3
PHP 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 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

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安装成功!

phpunit安装出错的原因及解决办法的更多相关文章

  1. jquery.min.map 404 (Not Found)出错的原因及解决办法

    Chrome 更新后出现了 jquery.min.map 404  (Not Found) 的信息 这个到底是什么东西?查询了一下,得到了以下资料 JQuery 官方解释 摘录一下內容 从 jQuer ...

  2. 整理 node-sass 安装失败的原因及解决办法

    npm install 时偶尔遇到报错:没有安装python或node-sass 安装失败的问题,百度之后发现是被墙了,但根据百度的方法换了淘宝镜像和用了vpn都安装失败,最后发现原来是因为没有卸载之 ...

  3. 整理Mac系统 node-sass 安装失败的原因及解决办法

    转载与:https://segmentfault.com/a/1190000010984731 声明:本文非原创,如有侵权请留言或发邮件告知,作者会立即停止侵权并删除本文.发布此文章主要是希望跟作者遇 ...

  4. javascirpt的json.stringify()方法在IE浏览器兼容性模式下出错的原因与解决办法

    今天开机混底薪的时候遇到一个JSON.stringify()在IE浏览器兼容模式下的问题. 问题描述 一个弹窗选择的功能原来好好的,突然就不行了. 想要调试调试不了,报错信息也看不到(一开F12这破I ...

  5. node-sass 安装失败的原因及解决办法

    出处:https://segmentfault.com/a/1190000010984731 windows 上用 yarn add node-sass --dev 也可以安装上.

  6. Visual Studio build tools 安装出错的一种解决办法

    一般是安装包丢失或损坏,那么我么可以用离线下载的方式来先行下载. 用 -h 看下帮助 主要是Layout参数. 下载完,到下载目录安装吧.

  7. python基础===Windows环境下使用pip install 安装出错"Cannot unpack file"解决办法

    不知道为什么,加了豆瓣镜像源还是不行 这个命令可以解决! pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douba ...

  8. (转)整理 node-sass 安装失败的原因及解决办法

    转载地址:https://segmentfault.com/a/1190000010984731

  9. zblog上传安装主题插件不成功的原因和解决办法

    最近有不少zblog用户反映在后台上传安装主题或者插件的时候出现了问题.本文就来尝试说明下这类问题的原因和解决办法. 首先来说说zblog主题或者插件的安装方法,一共有三种方式: 第一种是直接在网站后 ...

随机推荐

  1. vsftpd的配置文件说明

    vsftpd的配置文件说明: vsftpd.ftpusers:位于/etc目录下.它指定了哪些用户账户不能访问FTP服务器,例如root等. vsftpd.user_list:位于/etc目录下.该文 ...

  2. 初入码田--ASP.NET MVC4 Web应用之创建一个空白的MVC应用程序

    初入码田--ASP.NET MVC4 Web应用开发之一  实现简单的登录 初入码田--ASP.NET MVC4 Web应用开发之二 实现简单的增删改查 2016-07-29 在此之前,需要一台电脑( ...

  3. SQL有三个类型的索引,唯一索引 不能有重复,但聚集索引,非聚集索引可以有重复

    重要: (1) SQL如果创建时候,不指定类型那么默认是非聚集索引 (2) 聚集索引和非聚集索引都可以有重复记录,唯一索引不能有重复记录. (3) 主键 默认是加了唯一约束的聚集索引,但是也可以在主键 ...

  4. python3 执行AES加密方法

    cmd执行命令:pip install pycryptodome # -*- coding: utf-8 -*- # __author__ = 'Carry' import base64 from C ...

  5. 把打印的内容保存成文件(PDF)

    有时候网页的内容和打印的内容会有一些差异,需要把打印的内容倒出来.是有办法的. 1.以谷歌为内核的浏览器示例,按Ctrl+p快捷键打开打印对话框,如图: 2.点击更改按钮,更改打印机,会出现选择目标打 ...

  6. springboot学习笔记-3 整合redis&mongodb

    一.整合redis 1.1 建立实体类 @Entity @Table(name="user") public class User implements Serializable ...

  7. YARN的重启动问题:RM Restart/RM HA/Timeline Server/NM Restart

    ResourceManger Restart ResourceManager负责资源管理和应用的调度,是YARN的核心组件,有可能存在单点失败的问题.ResourceManager Restart是使 ...

  8. Android CollapsingToolbarLayout

    第一次看到这种用户体验是在Google Play Store App的应用详情的Activity中. 大的Banner图,能第一时间吸引用户的眼球,用不一样的Banner大图更具个性化的展示内容.图总 ...

  9. js关闭当前页面窗口的问题

    有两种情况,如果当前页面窗口是由js代码打开的,那么可以直接用js关闭该窗口 如: window.close(); 如果该页面是由用户输入地址直接进去的,直接close是会无效的,此时需要这样做: w ...

  10. Centos7搭建redis集群及安装sentinel

    准备三个节点,系统版本为CentOS7.3 11.0.8.15 master 11.0.8.16 slave01 11.0.8.17 slave02 1.安装redis # yum install - ...