使用Apache + PHP发送邮件时遇到权限错误,但不想将权限更改为777。

3

我无法让apache+php发送邮件,除非将/var/spool/clientmqueue的权限更改为777。

/var/spool/clientmqueue的所有权

drwxrwxrwx 2 smmsp mail 4096 Jul 19 11:50 clientmqueue

我已经涉及了针对smmsp和Apache的用户组。

id apache
uid=48(apache) gid=48(apache) groups=48(apache),12(mail)

id mail
uid=12(mail) gid=12(mail) groups=12(mail),48(apache)

SELinux被禁用了

getsebool httpd_can_sendmail
getsebool: SELinux is disabled

在邮件日志中,如果我将文件夹权限设置为770

NOQUEUE: SYSERR(apache): can not write to queue directory
/var/spool/clientmqueue/ (RunAsGid=48, required=12): Permission denied

如果我不发送邮件,php会报错。

如果我将文件夹设置为0777,则在邮件日志中会看到以下内容。

dangerous permissions=40776 on queue directory /var/spool/clientmqueue/

但是 PHP 可以正常发送邮件。

如果将权限设置为 0770,让 Apache 在 mail 组中被读取,是否可以使其工作?我知道错误出在获取 Apache 的主 GID 48 上,但它也共享组 12。

任何帮助都将不胜感激。

2个回答

2

这个对我很有帮助。在Ubuntu机器上,我遇到了其他错误,然后才遇到了这个。我来分享一下,以防其他人也遇到同样的问题。我收到了 NOQUEUE: SYSERR(www-data): can not chdir(/var/spool/mqueue-client/): Permission denied. 的报错信息。

usermod -a -G smmsp www-data
chmod 770 /var/spool/mqueue-client     (don't use 775, it gives dangerous permission error in the log)
service apache2 restart (this is required for the above to take effect)
Now sending email gives a different error.
- NOQUEUE: SYSERR(www-data): can not write to queue directory /var/spool/mqueue-client/
- chmod 4555 /usr/sbin/sendmail
- Above command fixed the email issue. => didn't see any error in the mail.log this time.

1
今天我也遇到了完全相同的问题(并且来到这里寻找答案)。
最终我找到了这个概述;从那个列表中运行以下命令解决了我的问题:
chmod 4555 /usr/sbin/sendmail

这将在sendmail二进制文件上设置setuid特殊模式,可能允许Apache以邮件用户的身份发送邮件。

(在运行此命令后,我重新启动了apache和sendmail守护程序,尽管我不确定哪个实际上需要重新启动)

然而,我仍然非常好奇是什么导致了这个问题...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接