PHP Warning: ldap_bind(): Unable to bind to server: Can’t contact LDAP server

ldapPHP

I've following problem with my php script:

PHP Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in ….

ldap_connect() says "Success" but ldap_bind() fails, how to fix that issue?

Best Answer

Had this error on RHEL7 ( CentOS7 ) due to SELinux restricting ports HTTPD can use.

LDAP ports 389 and 636 are not on the default allow list, you can unblock with:

setsebool -P httpd_can_network_connect 1

You can test for the restriction by trying a socket to the LDAP server:

fsockopen('LDAP-Server-IP', 389);

It will give 'Permission Denied' showing it's blocked and not a credentials issue.

Also check your SELinux audit log file for other things being blocked.