简体   繁体   English

PHP的包含路径不起作用

[英]php include path doesnt work

My server uses Ubuntu with PHP5 and NginX. 我的服务器使用Ubuntu和PHP5和NginX。

I have installed pear using sudo apt-get install php-pear , and later uninstalled it using sudo pear uninstall pear . 我已经使用sudo apt-get install php-pear ,后来又使用sudo pear uninstall pear sudo apt-get install php-pear卸载了它。 Today I downloaded phpmailer using sudo apt-get install libphp-phpmailer . 今天,我使用sudo apt-get install libphp-phpmailer下载了sudo apt-get install libphp-phpmailer

I wrote code to send email with phpmailer. 我编写了使用phpmailer发送电子邮件的代码。 It begins with: 它始于:

require_once("class.phpmailer.php");

and I edit the php.ini both in /etc/php5/cli and in /etc/php5/fpm to set: 然后在/etc/php5/cli/etc/php5/fpm编辑php.ini进行设置:

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

It did work well if I execute this php program in command line, but if I visit this php page through my browser, it produce a HTML500 error, and I checked the error.log file, which shows: 如果我在命令行中执行此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 ...

I wander how comes this path? 我漫步这条路怎么走? I am sure I have edited the include_path in both php.ini files. 我确定我已经编辑了两个php.ini文件中的include_path Is there another configuration file I missed? 我还错过了另一个配置文件吗? Where does the string ".:/usr/share/php:/usr/share/pear" come from? 字符串".:/usr/share/php:/usr/share/pear"从何而来?

If you are absolutely sure all paths are correct then it could be a file permission issue. 如果您完全确定所有路径都正确,则可能是文件权限问题。

  1. Find out what user Nginx runs under. 找出运行Nginx的用户。 It will probably be nginx . 可能是nginx Run groups nginx and the output should be nginx : nginx , meaning the user nginx exists, and has only one group, which is also nginx. 运行groups nginx ,输出应为nginx : nginx ,这意味着用户nginx存在,并且只有一个组,该组也是nginx。
  2. On the command line navigate to the location of class.phpmailer.php and run ls -l to view the permissions of the files in that directory. 在命令行上,导航到class.phpmailer.php的位置,然后运行ls -l来查看该目录中文件的权限。 Example output would be: -rw-r--r-- 1 someuser somegroup , meaning read and write access is granted to the owner (someuser), read access for the group (somegroup), and read access to everybody else. 输出示例如下: -rw-r--r-- 1 someuser somegroup ,这意味着向所有者(someuser)授予读和写访问权限,对该组(somegroup)具有读访问权限,并向其他所有人授予读访问权限。
  3. The user nginx (if that is what it is running under) needs to have read access to that file. 用户nginx(如果正在其下运行)需要对该文件具有读取权限。 So change the owner/permissions as necessary. 因此,根据需要更改所有者/权限。

If you need further explanation of how to do any of this just give me a shout and I will update this with further instructions. 如果您需要进一步说明如何执行此操作,请大声疾呼,我将通过进一步的说明进行更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM