为了账号安全,请及时绑定邮箱和手机立即绑定

CentOS 7 上的 PHP:LDAP 无法绑定到服务器

CentOS 7 上的 PHP:LDAP 无法绑定到服务器

PHP
慕尼黑8549860 2022-10-09 20:09:36
我有以下代码    public function openConnection()    {        $this->ldapServerHandle = ldap_connect(ConfigH::getConfig()->ldap->host);        $bindDN = ConfigH::getConfig()->ldap->serviceAccount->bindDN;        if ($this->ldapServerHandle) {            $this->ldapBindHandle = ldap_bind(                $this->ldapServerHandle,                $bindDN,                ConfigH::getConfig()->ldap->serviceAccount->password            );            if (!$this->ldapBindHandle) {                $errorMsg = "LDAP::__construct(): Could not bind the service account ".$bindDN;                LoggerH::emergency($errorMsg);                throw new LDAPException($errorMsg);            }        } else {            $errorMsg = "LDAP::__construct(): Could not connect to the LDAP server ".ConfigH::getConfig()->ldap->host;            LoggerH::emergency($errorMsg);            throw new LDAPException($errorMsg);        }    }问题从今天早上开始,我遇到了这个错误,让我很头疼:Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server [...]在 Windows 上一切正常,当我在 CentOS 生产服务器上执行代码时,它停止工作。我已经检查过的OpenLDAP 已安装并启用LDAP 服务器可从 CentOS 服务器访问(Kerberos 在同一台机器上没有遇到任何问题)我已经尝试过的重新安装了php-ldap扩展检查凭据和地址一百万次附加信息ConfigH::getConfig()->ldap->host 返回类似“adserver.ourcompany.com”的内容,这是我们的 LDAP 服务器的地址ConfigH::getConfig()->ldap->serviceAccount->bindDN 返回一个有效的绑定 DNConfigH::getConfig()->ldap->serviceAccount->password 返回服务账号的密码
查看完整描述

1 回答

?
梦里花落0921

TA贡献1772条经验 获得超6个赞

解决方案

使用 CentOS 的人获得 SELinux,是的。
在深入挖掘 Google(例如结果的第 4 页)和 Stackoverflow 之后,我发现问题是由 SELinux 限制httpd通过某些端口进行通信,尽管防火墙被配置为允许它,包括 LDAP 端口。

要允许httpd通过这些端口进行通信,请运行以下命令

setsebool -P httpd_can_network_connect 1

(这里的原始解决方案(WhoIsRich 的回答))


查看完整回答
反对 回复 2022-10-09
  • 1 回答
  • 0 关注
  • 127 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号