IT Comrade

""

Enable LDAP in PHP on Windows (Call to undefined function: ldap_connect())

Edit Post

Enable LDAP in PHP on Windows (Call to undefined function: ldap_connect())


I am new to LDAP concept. As any beginner might find, I was confronted by the error ‘Call to undefined function: ldap_connect()’ when I tried to run the basic php code below:

<?php

    echo "<h3>LDAP Connection test</h3>";

    echo "Connecting ...<br />";

    $ds=ldap_connect("ldap://yourldapserver");  // must be a valid LDAP server!

    echo "connect result is " . $ds . "<br />";

?>


Soon I learned that LDAP support for php need to be manually enabled. Below are the steps I have done to enable LDAP in PHP on windows XP (appserv)



  1. Check your php information if you are not sure of it. Access ‘http://yourserver/phpinfo.php’ (in my case) and check for the following:


    1. Configuration File (php.ini) Path  (C:\WINDOWS\php.ini)

    2. extension_dir    (C:\AppServ\php5\ext)


  2. Open php.ini and find the line 'extension=php_ldap.dll' and take out the semi-colon if it is there.

  3. Open that folder ‘extension_dir’ and ensure the php_ldap.dll is there.

  4. If it isn't then put it in there. If that still hasn't fixed it you are missing a supporting dll, but you don't get told that. To see what dlls are missing open the Command Prompt and navigate to the php directory and execute the following line 'php -m'. You should get some error messages now. Ugly, but at least they give you information! Find the dlls listed and copy them to the php directory. You may now need to restart the apache/httpd service. Run 'php -m' again and you should be error free. (I didn’t have to do this part)

  5. If the above steps didn’t solve your problem then now you need to


On Windows NT, 2000, XP and 2003:



On Windows 98/Me you need to edit the autoexec.bat file:



Note: Be sure to reboot after following the steps above to ensure that the PATH changes are applied.

The PHP manual used to promote the copying of files into the Windows system directory, this is because this directory (C:\Windows, C:\WINNT, etc.) is by default in the systems PATH. Copying files into the Windows system directory has long since been deprecated and may cause problems.

Sources:

http://docs.moodle.org/en/LDAP_authentication#Warning:_The_PHP_LDAP_module_does_not_seem_to_be_present._Please_ensure_it_is_installed_and_enabled.
http://docs.moodle.org/en/LDAP_authentication#Warning:_The_PHP_LDAP_module_does_not_seem_to_be_present._Please_ensure_it_is_installed_and_enabled.

http://th2.php.net/manual/en/faq.installation.php#faq.installation.addtopath

http://forums.devshed.com/php-development-5/fatal-error-call-to-undefined-function-ldap-connect-260273.html

Labels: , , , , , , ,

Posted by Alogger on Wednesday, June 20, 2007 at 7:22 PM. 1 Comments

Hi!
php_ldap also may require following libs: libeay32.dll and ssleay32.dll

Copy these libs into %win%/System32 folder.

Utilite named "depends" from MS Visual Studio tools can help you to know dependencies