ldap_connect returns false when called from the Apache module, but works fine when the PHP script is executed from the command line. I suspect the problem is somehow library or linker related, and not necessarily a PHP problem, but I am stumped. I would welcome any assistance.
Setup: Fedora Core 3 (2.6.9-1.724_FC3smp #1) Apache 1.3.33 (from source) PHP 5.0.4 (have also test with 4.3.10 and 4.3.11 -- all from source) OpenLDAP 2.2.24 When I run the script using the php command line - it works . . . connects, queries etc. When run from Apache, the ldap_connect function returns boolean(false). I have tried php 4.3.10, 4.3.11, 5.0.4 - and multiple versions of openldap from both RPM and source. Same result all various versions. I tracked down the exact line of the PHP C-source where the failure occurs: (ext/ldap/ldap.c) ldap = ldap_init(host, port); So in order to determine if the ldap_init failed legitimately or for some other reason I modified the openldap (open.c) ldap_init() function to always return a valid ldap structure. I recompiled everything - reinstalled, and the result was no different. So it would appear as though the libldap library isn't being made available to the Apache PHP module, but is available to the CLI PHP. Thanks for your assistance - detailed configuration information follows: -------------------------------------------------------------------------- When run from the command line: [EMAIL PROTECTED] test]# php ./ldap.php <h3>LDAP query test</h3>... Connecting ... resource(4) of type (ldap link) connect result is <pre> Resource id #4</pre><br />Binding ...Bind result is 1<br />Searching for username...Search result is Resource id #5<br />Number of entires returned is 1<br />Getting entries ...<p>Data for 1 items returned:<p>dn is: CN=username,OU=Users,OU=Company,DC=example,DC=com<br />first cn entry is: username<br />first email entry is: [EMAIL PROTECTED]<br /><hr />Closing connection -------------------------------------------------------------------------- When run from Apache: LDAP query test ... Connecting ... bool(false) connect result is Unable to connect to LDAP server?!? -------------------------------------------------------------------------- PHP configure settings: './configure' '--enable-versioning' '--enable-memo' '--enable-ctype' '--with-curl' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-freetype' '--with-t1lib' '--with-jpeg' '--with-jpeg-dir=/usr/local' '--with-png' '--with-xpm' '--with-gmp' '--with-mcrypt' '--with-mhash' '--with-mysql=/usr/local' '--with-openssl' '--with-oci8-instant-client' '--enable-overload' '--with-pcre-regex' '--enable-posix' '--enable-session' '--enable-tokenizer' '--with-expat' '--enable-xml' '--with-zlib' '--with-apxs=/usr/local/apache/bin/apxs' '--with-xpm-dir=/usr/X11R6/' '--with-freetype-dir=/usr' '--with-t1lib-dir=/usr' '--with-ldap' '--with-ldap-sasl=/usr' '--with-sybase-ct=/usr/local/FreeTDS/' -------------------------------------------------------------------------- ldconfig sees the ldap libraries . . . [EMAIL PROTECTED] ~]# ldconfig -p |grep -e ldap -e lber -e sasl libsasl2.so.2 (libc6) => /usr/lib/libsasl2.so.2 libsasl2.so (libc6) => /usr/lib/libsasl2.so libsasl.so.7 (libc6) => /usr/lib/libsasl.so.7 libsasl.so (libc6) => /usr/lib/libsasl.so libnss_ldap.so.2 (libc6) => /lib/libnss_ldap.so.2 libnss_ldap.so (libc6) => /usr/lib/libnss_ldap.so libldap_r-2.2.so.7 (libc6) => /usr/local/lib/libldap_r-2.2.so.7 libldap-2.2.so.7 (libc6) => /usr/local/lib/libldap-2.2.so.7 liblber-2.2.so.7 (libc6) => /usr/local/lib/liblber-2.2.so.7 -------------------------------------------------------------------------- The PHP code in question: <? // basic sequence with LDAP is connect, bind, search, interpret search // result, close connection echo "<h3>LDAP query test</h3>"; echo "... Connecting ... "; $server="domain-controller.example.com"; $ds=ldap_connect($server); // debugging . . . var_dump($ds); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); echo "connect result is <pre> "; print_r($ds); echo "</pre><br />"; if ($ds) { echo "Binding ..."; $r=ldap_bind($ds,"CN=username,OU=Users,OU=Company,DC=example,DC=com","password"); echo "Bind result is " . $r . "<br />"; echo "Searching for username"; // Search surname entry $sr=ldap_search($ds, "ou=Users,ou=company,dc=example,dc=com", "cn=username"); echo "Search result is " . $sr . "<br />"; echo "Number of entires returned is " . ldap_count_entries($ds, $sr) . "<br />"; echo "Getting entries ...<p>"; $info = ldap_get_entries($ds, $sr); echo "Data for " . $info["count"] . " items returned:<p>"; for ($i=0; $i<$info["count"]; $i++) { echo "dn is: " . $info[$i]["dn"] . "<br />"; echo "first cn entry is: " . $info[$i]["cn"][0] . "<br />"; echo "first email entry is: " . $info[$i]["mail"][0] . "<br /><hr />"; } echo "Closing connection"; ldap_close($ds); } else { echo "<h4>Unable to connect to LDAP server?!?</h4>"; } ?> --------------------------------------------------------------------------