【问题标题】:How can apache be allowed to send email?如何允许apache发送电子邮件?
【发布时间】:2012-09-30 01:38:17
【问题描述】:

我有一个运行 Apache 2.2 和 PHP 5.3 的 CentOS 6.2 虚拟机,我试图通过 PHP 的 mail() 函数发送电子邮件。我可以毫无问题地从 CLI 发送电子邮件,但是当 PHP 尝试时它会失败。在 sendmail 日志中如下:

Oct  9 11:42:03 localhost sendmail[3080]: NOQUEUE: SYSERR(apache): can not chdir(/var/spool/clientmqueue/): Permission denied

似乎 Apache 没有执行此操作的权限,但我不确定如何修复它。我发现了很多关于此的讨论,但没有足够具体到我可以使用的我正在做的事情。任何帮助,将不胜感激。 谢谢!

【问题讨论】:

  • 您想如何发送这封电子邮件? Apache 永远不需要 chdir 进入邮件假脱机目录 - 它应该只与本地邮件 MTA 对话。

标签: php linux apache centos sendmail


【解决方案1】:

您可能启用了 SELinux。

http://selinuxproject.org/page/Main_Page

您可以通过以下方式检查 SELinux 状态:

状态

您应该会看到如下内容:

SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

您可以通过以下方式暂时关闭 SELinux:

echo 0 >/selinux/enforce

然后用

echo 1 >/selinux/enforce

如果你做临时。关闭它,不要安装 RPM 或进行更改。我发现这可能会导致重新启用它时出现问题。

如果您想永久禁用 SELinux,请尝试:

https://access.redhat.com/knowledge/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-Enabling_and_Disabling_SELinux.html

【讨论】:

    【解决方案2】:

    首先您必须检查权限是否正确。这是我系统中的以下权限

    # ls -l /usr/sbin/sendmail.sendmail -r-xr-sr-x root smmsp /usr/sbin/sendmail.sendmail

    # ls -l /var/spool/clientmqueue drwxrwx--- smmsp smmsp /var/spool/clientmqueue

    如果您的权限或所有权错误,请使用 chown 和 chmod 进行更改。

    如果上述正确,则禁用 selinux,或者如果您希望启用 selinux,请使用 chcon 设置正确的 selinux 上下文。

    http://docs.fedoraproject.org/en-US/Fedora/13/html/Security-Enhanced_Linux/sect-Security-Enhanced_Linux-Working_with_SELinux-SELinux_Contexts_Labeling_Files.html

    要暂时禁用selinux,请使用#setenforce 0

    【讨论】:

    • 不要禁用 SELinux :( 有一个布尔值 httpd_can_sendmail 允许网络服务器发送在这种情况下应该工作的邮件。使用 setsebool -P httpd_can_sendmail 1 设置它,并包括 -P使其在重新启动后保持不变的选项。
    【解决方案3】:

    Selinux 可能会导致问题,验证运行:

    getsebool -a | grep mail
    

    如果显示如下就是selinux:

    allow_postfix_local_write_mail_spool --> off
    

    你可以禁用它,但如果你想保留它(你应该这样做,因为它提供了额外的安全层)你应该做其他事情:

    setsebool -P httpd_can_sendmail on
    

    这将允许 httpd 发送电子邮件,就像您使用 php mail() 时一样。

    【讨论】:

    • -P 选项使它成为永久的,所以重启后它会再次打开:)
    • 我只使用了“setsebool -P httpd_can_sendmail on”并解决了这个问题。谢谢
    【解决方案4】:

    讨厌死掉这个,但这里没有一个解决方案对我有用。我对 SELinux 知之甚少,但我最终发现了这个问题(在 CentOS 6 上):

    getsebool httpd_can_sendmail
    

    告诉我它已禁用。修复了

    setsebool httpd_can_sendmail 1
    

    【讨论】:

    • setsebool 没有 -P 将无法在重新启动后继续存在。所以应该使用-P。
    【解决方案5】:
    getsebool -a | grep mail
    allow_postfix_local_write_mail_spool --> off
    setsebool -P httpd_can_sendmail on
    

    这个命令对我有用。

    【讨论】:

      猜你喜欢
      • 2011-03-07
      • 2022-07-17
      • 1970-01-01
      • 2017-09-14
      • 1970-01-01
      • 2022-07-24
      • 1970-01-01
      • 2021-07-10
      • 1970-01-01
      相关资源
      最近更新 更多