PHP-设置所有权后出现“无法打开流:权限被拒绝”错误

时间:2019-04-12 15:38:17

标签: php email pear

我正在尝试使用pear的邮件类,但是我的脚本无权访问安装了它的主文件夹中的Mail.php,并且我已经正确地对需要访问的文件执行了chown命令。 ,这是我的php脚本的样子:

<?php

require_once "/home/ec2-user/pear/share/pear/Mail.php";

if (isset($_GET['trade']))
{

我得到的错误是:

Warning:  require_once(/home/ec2-user/pear/share/pear/Mail.php): failed to open stream: Permission denied in /var/www/html/newslookup/email.php on line 5
Fatal error:  require_once(): Failed opening required '/home/ec2-user/pear/share/pear/Mail.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/newslookup/email.php on line 5

在这里显示我已经安装了pear,并且已经正确执行了chown命令:

[ec2-user@ip-172-31-90-218 ~]$ pwd
/home/ec2-user

[ec2-user@ip-172-31-90-218 ~]$ sudo chown -R ec2-user:apache pear   // here 

[ec2-user@ip-172-31-90-218 ~]$ ls -alrt
total 32
-rw-r--r--  1 ec2-user ec2-user  231 Jul 27  2018 .bashrc
-rw-r--r--  1 ec2-user ec2-user  193 Jul 27  2018 .bash_profile
-rw-r--r--  1 ec2-user ec2-user   18 Jul 27  2018 .bash_logout
drwxr-xr-x  3 root     root       22 Jan 29 02:19 ..
-rw-------  1 ec2-user ec2-user 2067 Feb 17 22:24 .viminfo
drwxrwxr-x  3 ec2-user ec2-user   19 Mar 25 20:44 .local
drwxrwxr-x  3 ec2-user ec2-user   22 Mar 25 20:44 .config
drwxrwxr-x  3 ec2-user ec2-user   22 Mar 25 20:44 .cache
drwx------  2 ec2-user ec2-user   80 Mar 25 21:49 .ssh
-rw-------  1 ec2-user ec2-user 9997 Apr 11 18:50 .bash_history
-rw-rw-r--  1 ec2-user ec2-user  611 Apr 12 14:18 .pearrc
drwx------  8 ec2-user ec2-user  193 Apr 12 14:18 .
drwxrwxr-x 10 ec2-user apache    122 Apr 12 14:19 pear  // as you can see my pear folder has the correct permissions.

[ec2-user@ip-172-31-90-218 ~]$ cd pear
[ec2-user@ip-172-31-90-218 pear]$ ls
bin  cfg  data  docs  man  php.ini-gopear  share  tests  www

[ec2-user@ip-172-31-90-218 pear]$ cd share
[ec2-user@ip-172-31-90-218 share]$ ls
pear

[ec2-user@ip-172-31-90-218 share]$ cd pear
[ec2-user@ip-172-31-90-218 pear]$ ls -alrt
total 108
drwxrwxr-x  3 ec2-user apache    18 Apr 12 14:18 ..
drwxrwxr-x  3 ec2-user apache   108 Apr 12 14:18 .channels
drwxrwxr-x  2 ec2-user apache    21 Apr 12 14:18 Archive
drwxrwxr-x  2 ec2-user apache    24 Apr 12 14:18 Console
drwxrwxr-x  3 ec2-user apache    36 Apr 12 14:18 Structures
drwxrwxr-x  2 ec2-user apache    22 Apr 12 14:18 XML
drwxrwxr-x  2 ec2-user apache    23 Apr 12 14:18 OS
-rw-rw-r--  1 ec2-user apache 20562 Apr 12 14:18 System.php
-rw-rw-r--  1 ec2-user apache  1049 Apr 12 14:18 peclcmd.php
-rw-rw-r--  1 ec2-user apache 35467 Apr 12 14:18 PEAR.php
-rw-rw-r--  1 ec2-user apache 15052 Apr 12 14:18 pearcmd.php
drwxrwxr-x 11 ec2-user apache  4096 Apr 12 14:18 PEAR
drwxrwxr-x  5 ec2-user apache   214 Apr 12 14:21 .registry
drwxrwxr-x  2 ec2-user apache   126 Apr 12 14:21 Mail
-rw-rw-r--  1 ec2-user apache     0 Apr 12 14:21 .lock
-rw-rw-r--  1 ec2-user apache  7542 Apr 12 14:21 .filemap
-rw-rw-r--  1 ec2-user apache     0 Apr 12 14:21 .depdblock
-rw-rw-r--  1 ec2-user apache  2727 Apr 12 14:21 .depdb
-rw-rw-r--  1 ec2-user apache  9878 Apr 12 14:40 Mail.php    // Mail.php should be accessible by my script. 
drwxrwxr-x 11 ec2-user apache   282 Apr 12 14:40 .

该脚本通过单击按钮通过JavaScript运行。

谁能告诉我为什么执行chown命令后会出现权限错误?

1 个答案:

答案 0 :(得分:2)

我将其移至一个答案,因为这似乎是通过仔细检查日志来解决您的问题的解决方案。

chmod -R 755 pear

Chmod 755设置文件的755权限。 755表示所有者的完全权限,而他人则具有读取和执行权限。

换句话说,仅仅因为您是所有者,并不意味着您拥有权限。