PHP 包含路径不起作用


php include path doesnt work

我的服务器使用带有PHP5和NginX的Ubuntu。

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

我编写了代码来使用phpmailer发送电子邮件。它以以下内容开头:

require_once("class.phpmailer.php");

我用/etc/php5/cli/etc/php5/fpm编辑php.ini以设置:

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. 找出Nginx在什么用户下运行。可能会nginx.运行groups nginx,输出应该是nginx : nginx的,这意味着用户nginx存在,并且只有一个组,也是nginx。
  2. 在命令行上导航到class.phpmailer.php的位置并运行ls -l以查看该目录中文件的权限。示例输出为:-rw-r--r-- 1 someuser somegroup ,表示向所有者(某个用户)授予读取和写入访问权限,为组(某个组)授予读取访问权限,向其他所有人授予读取访问权限。
  3. 用户nginx(如果这是它正在运行的内容)需要对该文件的读取访问权限。因此,请根据需要更改所有者/权限。

如果您需要有关如何执行此操作的进一步解释,请给我大喊大叫,我将通过进一步的说明对其进行更新。