php包含路径不起作用

时间:2016-01-26 15:51:49

标签: php nginx

我的服务器使用Ubuntu和PHP5以及NginX。

我使用sudo apt-get install php-pear安装了pear,后来使用sudo pear uninstall pear将其卸载。今天我使用sudo apt-get install libphp-phpmailer下载了phpmailer。

我编写了用phpmailer发送电子邮件的代码。它始于:

require_once("class.phpmailer.php");

我在php.ini/etc/php5/cli中编辑了/etc/php5/fpm以设置:

include_path = ".:/usr/share/php/libphp-phpmailer"

如果我在命令行中执行这个php程序,它确实运行良好,但是如果我通过浏览器访问这个php页面,它会产生HTML500错误,我检查了error.log文件,其中显示:

PHP message: PHP Fatal error: require_once(): 
Failed opening required 'class.phpmailer.php' 
(include_path='.:/usr/share/php:/usr/share/pear') in ...

我喜欢这条道路怎么样?我确信我已在两个php.ini文件中编辑了include_path。我错过了另一个配置文件吗?字符串".:/usr/share/php:/usr/share/pear"来自哪里?

1 个答案:

答案 0 :(得分:0)

如果您完全确定所有路径都正确,则可能是文件权限问题。

  1. 找出Nginx运行的用户。它可能是groups nginx。运行nginx : nginx,输出应该是class.phpmailer.php,这意味着用户nginx存在,并且只有一个组,也就是nginx。
  2. 在命令行上导航到ls -l的位置并运行-rw-r--r-- 1 someuser somegroup以查看该目录中文件的权限。示例输出为:&&,表示对所有者(someuser)授予读写访问权限,对组(某个组)具有读访问权限,对其他所有人具有读访问权限。
  3. 用户nginx(如果它正在运行的那个)需要具有对该文件的读访问权。因此,根据需要更改所有者/权限。
  4. 如果您需要进一步解释如何做到这一点,请给我一个喊叫,我会更新此说明。