Reputation: 596
I am using OpenLDAP and trying to connect (and bind) to ldap using the below mentioned PHP code from another server and its failing. But using this code, its connecting (and binding) successfully from the same server.
$ldaphost = "server_name"; // 127.0.0.1 when using same server and changing the value when using different server
$ldapport = 389;
$ldapconn = ldap_connect($ldaphost, $ldapport);
if ($ldapconn) {
echo 'Connected <br/>';
$userdn = "cn=manager,ou=Team,dc=example,dc=com";
$password = "password";
$bind = ldap_bind($ldapchtgoponn, $userdn, $password);
if ($bind) {
echo "Bind Successful";
} else {
echo "Error in bind";
}
}
Do i need to set anything to connect with LDAP from different server?
Upvotes: 0
Views: 2556
Reputation: 12131
not sure if you use OpenLDAP or other ldap-compliant server, but for OpenLDAP (slapd), you should not need to do any special configuration steps to be able to connect to the server from a remote machine - the server listens on all available network interfaces on ports 389 ( ldap:// ) and 636 ( ldaps:// - ldap over SSL ).
You can read more about network config for slapd here.
I suspect you have either a network, DNS resolution or firewall problem.
Try using telnet
to check the network connection from a terminal client or Command Prompt, like this:
telnet YOUR_SERVER_ADDRESS 389
You should get a bunch of nonsense from the ldap server and the telnet client should wait for your further input. If you see anything else, like connection refused and the telnet client exits it means there is firewall blocking your communication or you cannot contact the remote machine. Or, you have configured the slapd client to listen only on specific interfaces or IP addresses.
I recommend trying the telnet command with an IP address instead of DNS hostname to eliminate any possible DNS-related issues.
Upvotes: 2