Linux 如何允许 apache 发送电子邮件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12804841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can apache be allowed to send email?
提问by dev_willis
I have a CentOS 6.2 virtual machine running Apache 2.2 and PHP 5.3 that I'm trying to send email from via PHP's mail() function. I can send email from the CLI without problems but when PHP tries it fails. In the sendmail log is the following:
我有一台运行 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
It seems like Apache doesn't have permission to do this but I'm not sure how to fix it. I've found a lot discussion about this but nothing specific enough to what I'm doing that I could use. Any help would be appreciated. Thanks!
Apache 似乎无权执行此操作,但我不确定如何解决。我发现了很多关于此的讨论,但没有足够具体到我正在做的事情可以使用。任何帮助,将不胜感激。谢谢!
采纳答案by Ranjith Ruban
First you have to check if permission are correct. Here is the permission below in my system
首先,您必须检查权限是否正确。这是我系统中的以下权限
# ls -l /usr/sbin/sendmail.sendmail
-r-xr-sr-x root smmsp /usr/sbin/sendmail.sendmail
# 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
# ls -l /var/spool/clientmqueue
drwxrwx--- smmsp smmsp /var/spool/clientmqueue
If your permissions or ownership is wrong then change it using chown and chmod.
如果您的权限或所有权错误,请使用 chown 和 chmod 更改它。
If the above is right then disable selinux or if you want selinux enabled use chcon to set the correct selinux context.
如果以上正确,则禁用 selinux 或者如果您希望启用 selinux,请使用 chcon 设置正确的 selinux 上下文。
For disabling selinux temporarily use #setenforce 0
暂时禁用 selinux 使用 #setenforce 0
回答by jeffatrackaid
You may have SELinux enabled.
您可能启用了 SELinux。
http://selinuxproject.org/page/Main_Page
http://selinuxproject.org/page/Main_Page
You can check SELinux status by doing:
您可以通过执行以下操作来检查 SELinux 状态:
sestatus
状态
You should see something like:
你应该看到类似的东西:
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted
You can turn SELinux off temporarily via:
您可以通过以下方式暂时关闭 SELinux:
echo 0 >/selinux/enforce
and back on with
然后继续
echo 1 >/selinux/enforce
If you do temp. turn it off, do not install RPMs or make changes. I find this can lead to problems with re-enabling it.
如果你做温度。关闭它,不要安装 RPM 或进行更改。我发现这可能会导致重新启用它的问题。
If you want to permanently disable SELinux, then try:
如果您想永久禁用 SELinux,请尝试:
回答by Florin Sima
Selinux may cause the issue, to verify run:
Selinux 可能会导致此问题,请验证运行:
getsebool -a | grep mail
If it displays as bellow it is selinux:
如果显示如下,则是 selinux:
allow_postfix_local_write_mail_spool --> off
You may disabled it, but if you want to keep it (and you should as it provides an extra layer of security) you should do something else:
你可以禁用它,但如果你想保留它(你应该这样做,因为它提供了额外的安全层)你应该做一些其他的事情:
setsebool -P httpd_can_sendmail on
This will allow the httpd to send emails, as when you use php mail().
这将允许 httpd 发送电子邮件,就像您使用 php mail() 一样。
回答by jmaculate
Hate to necro this, but none of the solutions here worked for me. I know very little about SELinux, but I ended up discovering the problem with this (on CentOS 6):
讨厌死掉这个,但这里没有一个解决方案对我有用。我对 SELinux 知之甚少,但我最终发现了这个问题(在 CentOS 6 上):
getsebool httpd_can_sendmail
Which told me it's disabled. Fixed with
这告诉我它已禁用。固定与
setsebool httpd_can_sendmail 1
回答by Sawan Choubisa
getsebool -a | grep mail
allow_postfix_local_write_mail_spool --> off
setsebool -P httpd_can_sendmail on
This command working for me.
这个命令对我有用。