Enable LDAP in PHP on Windows (Call to undefined function: ldap_connect())
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)
- Check your php information if you are not sure of it. Access ‘http://yourserver/phpinfo.php’ (in my case) and check for the following:
- Configuration File (php.ini) Path (C:\WINDOWS\php.ini)
- extension_dir (C:\AppServ\php5\ext)
- Open php.ini and find the line 'extension=php_ldap.dll' and take out the semi-colon if it is there.
- Open that folder ‘extension_dir’ and ensure the php_ldap.dll is there.
- 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)
- If the above steps didn’t solve your problem then now you need to
On Windows NT, 2000, XP and 2003:
- Go to Control Panel and open the System icon (Start -> Settings -> Control Panel -> System, or just Start -> Control Panel -> System for Windows XP/2003)
- Go to the Advanced tab
- Click on the 'Environment Variables' button
- Look into the 'System Variables' pane
- Find the Path entry (you may need to scroll to find it)
- Double click on the Path entry
- Enter your PHP directory at the end, including ';' before (e.g. ; C:\AppServ\php5)
- Press OK and restart your computer
On Windows 98/Me you need to edit the autoexec.bat file:
- Open the Notepad (Start -> Run and enter notepad)
- Open the C:\autoexec.bat file
- Locate the line with PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;..... and add: ; C:\AppServ\php5 to the end of the line
- Save the file and restart your computer
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: appserv, code, computer, ldap, php, server, software, windows
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