简体   繁体   中英

PHP5-ldap and LDAPS under Apache2 (not working) vs CLI (working)

I'm trying to connect to an LDAPS server using Apache2, PHP5.3, with the php5-ldap package.

When I set the code off using PHP-CLI, it works fine.

When I execute the same code under Apache2, the bind always fails.

I've set TLS_REQCERT to NEVER, hence the CLI version working.

What am I doing wrong?

Code:

<?php

   // using anonymous ldap bind
   // connect to ldap server
   $ldapconn = ldap_connect("ldaps://XXX.XXX.com")
       or die("Could not connect to LDAP server.");

   if ($ldapconn)
   {
       // binding anonymously
       $ldapbind = ldap_bind($ldapconn) or die("Couldn't bind\n");

       if ($ldapbind) {
           echo "LDAP anonymous bind successful...";
       } else {
           echo "LDAP anonymous bind failed...";
       }
   }

   $res = ldap_search($ldapconn, 'ou=XXX,o=XXX', '(sn=XXX*)');
   $info = ldap_get_entries($ldapconn, $res);

   echo "<pre>" . var_dump($info) . "</pre>";

   ldap_unbind($ldapconn);

?>

Review php.ini, and make sure the ext is being loaded with phpinfo(). Differint sapi's might try loading php.ini from differint locations, so also check the location of php.ini within phpinfo() and make sure it's loading the one your expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM