I have the following code
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);
}
}
The issue
I have this error causing me headaches since this morning:
Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server [...]
Everything worked fine on Windows, when I executed the code on our CentOS production server, it stopped working.
What I have already checked
- OpenLDAP is installed and enabled
- The LDAP server is reachable from the CentOS server (Kerberos is experiencing no issues on the same machine)
What I have already tried
- Re-installed the
php-ldapextension - Checked the credentials and the address a milion times
Additional information
- ConfigH::getConfig()->ldap->host returns something like "adserver.ourcompany.com", which is the address of our LDAP server
- ConfigH::getConfig()->ldap->serviceAccount->bindDN returns a valid bind DN
- ConfigH::getConfig()->ldap->serviceAccount->password returns the password of the service account