简体   繁体   中英

php include path doesnt work

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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