dongshi1424 2016-01-26 15:51
浏览 94

php包含路径不起作用

My server uses Ubuntu with PHP5 and NginX.

I have installed pear using sudo apt-get install php-pear, and later uninstalled it using sudo pear uninstall pear. Today I downloaded phpmailer using sudo apt-get install libphp-phpmailer.

I wrote code to send email with 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:

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 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. Is there another configuration file I missed? Where does the string ".:/usr/share/php:/usr/share/pear" come from?

  • 写回答

1条回答 默认 最新

  • duansha6410 2016-01-26 16:13
    关注

    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. It will probably be 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.
    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. 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.
    3. The user nginx (if that is what it is running under) needs to have read access to that file. 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.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分