blu
blu

Reputation: 393

ldap_bind doesn't work on CentOS7 but works on Mac MAMP, What am I missing?

I'm trying to make a simple ldap bind that for some reason works on MAMP stack but not when I copy the code over to CentOS7. I installed the LDAP module for php.

    <?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

  if(extension_loaded('ldap')){
    print "LDAP Module enabled<br>";
  }

  $ldaphost = "ldap://ldap.myschool.edu";
  $ldapconn = ldap_connect($ldaphost)
            or die("Could not connect to {$ldaphost}");

  if($ldapconn){
    echo "LDAP Connections Success...<br>";
  }
  $ldaprdn = '[email protected]';
  $ldappass = 'password';

  if($ldapconn){
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
    var_dump($ldapbind);
    if ($ldapbind) {
        echo "LDAP bind successful...<br>";
    } else {
        echo "LDAP bind failed...<br>";
    }
  }



 ?>

I'm not sure why it works on MAMP and not CentOS7. I tried disabling the firewall, and giving apache full read write execute but that doesn't seem to be the case. Is there another package i need to install? The LDAP server is different from the server running this script if that helps.

Upvotes: 1

Views: 242

Answers (1)

Mark Shaw
Mark Shaw

Reputation: 140

Login to the server (the one the code is being executed on) and run this command:

getsebool -a| grep http | grep ldap

It should return something like this:

httpd_can_connect_ldap --> on

If it returns off instead off on then run this:

setsebool -P httpd_can_connect_ldap on

This will allow the server to connect to ldap over http

Upvotes: 1

Related Questions