CentOS 7,通过 apache 的 php 脚本不解析主机名。如果我直接使用 ip 就可以了
CentOS 7, php script via apache doesn't resolve host names. If I use ip directly it works
我已经在 CentOS 7 上安装了 LAMP 堆栈。
如果我尝试通过 php 从命令行解析名称,它会起作用,但如果我通过网络服务器执行该脚本,它不会解析名称。如果我直接使用 ip 它在每种情况下都有效。
例如:
$ip = gethostbyname('www.google.com');
echo "GOOGLE IP = " . $ip; // it shows IP only via php-cli, not thru apache
有什么想法吗?
编辑:禁用 SE 强制执行它有效。了解如何配置它以启用 SE 强制执行会很有用。
将 SELinux 设置为宽容
setenforce 0
确保安装了 selinux-policy、selinux-policy-devel、setroubleshoot-server、setroubleshoot
yum install selinux-policy, selinux-policy-devel, setroubleshoot-server, setroubleshoot -y
然后 tail 消息文件和 grep for sealert
tailf /var/log/messages | grep sealert
您的 SELinux 问题将以
的形式吐出
hostname setroubleshoot: SELinux is preventing httpd (httpd_t) "getattr" to /var/www/html/file1 (samba_share_t). For complete SELinux messages. run sealert -l 84e0b04d-d0ad-4347-8317-22e74f6cd020
所以您只需 运行 sealert -l 84e0b04d-d0ad-4347-8317-22e74f6cd020
查看您的 SELinux 问题
一旦您认为您已经解决了问题,请重新启用 SELinux setenforce 1
并检查您的问题是否已解决。如果不是,则重复这些步骤。
有关 sealert 的更多信息可在 Red Hat's website 找到,只是不要禁用 SELinux。
我已经在 CentOS 7 上安装了 LAMP 堆栈。
如果我尝试通过 php 从命令行解析名称,它会起作用,但如果我通过网络服务器执行该脚本,它不会解析名称。如果我直接使用 ip 它在每种情况下都有效。
例如:
$ip = gethostbyname('www.google.com');
echo "GOOGLE IP = " . $ip; // it shows IP only via php-cli, not thru apache
有什么想法吗?
编辑:禁用 SE 强制执行它有效。了解如何配置它以启用 SE 强制执行会很有用。
将 SELinux 设置为宽容
setenforce 0
确保安装了 selinux-policy、selinux-policy-devel、setroubleshoot-server、setroubleshoot
yum install selinux-policy, selinux-policy-devel, setroubleshoot-server, setroubleshoot -y
然后 tail 消息文件和 grep for sealert
tailf /var/log/messages | grep sealert
您的 SELinux 问题将以
的形式吐出hostname setroubleshoot: SELinux is preventing httpd (httpd_t) "getattr" to /var/www/html/file1 (samba_share_t). For complete SELinux messages. run sealert -l 84e0b04d-d0ad-4347-8317-22e74f6cd020
所以您只需 运行 sealert -l 84e0b04d-d0ad-4347-8317-22e74f6cd020
查看您的 SELinux 问题
一旦您认为您已经解决了问题,请重新启用 SELinux setenforce 1
并检查您的问题是否已解决。如果不是,则重复这些步骤。
有关 sealert 的更多信息可在 Red Hat's website 找到,只是不要禁用 SELinux。