我有以下代码
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 返回一个有效的绑定 DN
ConfigH::getConfig()->ldap->serviceAccount->password 返回服务账号的密码
梦里花落0921