47

I get this error when using WAMP:

Fatal error: Call to undefined function: ldap_connect()

I have already edited the php.ini folder and enabled php_ldap.dll.

For some reason only some of the extensions show up in phpinfo() when I turn them on. I have restarted Apache and restarted my computer.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Josh M
  • 982
  • 1
  • 7
  • 19

6 Answers6

123

If you are a Windows user, this is a common error when you use XAMPP since LDAP is not enabled by default.

You can follow this steps to make sure LDAP works in your XAMPP:

  • [Your Drive]:\xampp\php\php.ini: In this file uncomment the following line:

     extension=php_ldap.dll
    
  • Move the file: libsasl.dll, from [Your Drive]:\xampp\php to [Your Drive]:\xampp\apache\bin (Note: moving the file is needed only for XAMPP prior to version: 5.6.28)

  • Restart Apache.

  • You can now use functions of the LDAP Module!

If you use Linux:

For php5:

sudo apt-get install php5-ldap

For php7:

sudo apt-get install php7.0-ldap

If you are using the latest version of PHP you can do

sudo apt-get install php-ldap

running the above command should do the trick.

if for any reason it doesn't work check your php.ini configuration to enable ldap, remove the semicolon before extension=ldap to uncomment, save and restart Apache

levis
  • 462
  • 6
  • 16
sushant-hiray
  • 1,838
  • 2
  • 21
  • 28
3

Add path of your PHP to Windows System Path. The path should contain php.exe.

After adding the path open a new command prompt and make sure php.exe is in path by typing

C:\>php --help

Once you see proper help message from above, enable the php_ldap.dll extension in php.ini

Also copy php_ldap.dll from php/ext directory to apache/bin folder

Restart wamp and phpinfo() will now show ldap enabled.

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116
HimalayanCoder
  • 9,630
  • 6
  • 59
  • 60
0
  • [Your Drive]:\xampp\php\php.ini: In this file uncomment the following line:

    extension=php_ldap.dll

  • Move the file: libsasl.dll, from [Your Drive]:\xampp\php to [Your Drive]:\xampp\apache\bin Restart Apache. You can now use functions of the LDAP Module!

Sakawa Bob
  • 17
  • 3
0

Open the XAMMP php.ini file (the default path is C:\xammp\php\php.ini) and change the code (;extension=ldap) to extension=php_ldap.dll and save. Restart XAMMP and save.

php.ini

; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
;   extension folders as well as the separate PECL DLL download (PHP 5+).
;   Be sure to appropriately set the extension_dir directive.
;
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
extension=php_ldap.dll
0

My server is Windows Server 2016 with Apache 2.4, and I was having this error too. Move the file libsasl.dll, from C:\php to C:\apache\bin and Restart Apache.

ozahorulia
  • 9,798
  • 8
  • 48
  • 72
True.x
  • 1
0

Thank you all for your contributions. For my part, I needed to act on the 3 following points to make ldap_connect() work in PHP8.2.3 :

  1. add php_ldap.dll to php.ini
  2. copy libsasl.dll from PHP to APACHE
  3. add the PHP path to the PATH environment variable then restart APACHE
BRO_THOM
  • 824
  • 9
  • 24
Napets
  • 1