Fatal Error: Call to Undefined Function: Ldap_Connect()

Fatal error: Call to undefined function: ldap_connect()

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

Fatal error: Call to undefined function ldap_connect() in ubuntu

Make sure the LDAP extension is installed and enabled. This answer assumes you have PHP5, however, things should work similarly for PHP7 as well.

Install LDAP Extension

There should be a package named like php5-ldap:

aptitude show php5-ldap
Paquet : php5-ldap
...
Description : LDAP module for php5
This package provides a module for LDAP functions in PHP scripts.

Thus, the package can usually be installed like:

sudo apt-get install php5-ldap

If you do not use apt-get, use the equivalent command for the package manager you use.

Enable LDAP Extension

To enable the package after installation, you can use this command:

sudo php5enmod ldap

If you get any error message from the above command, it means something went wrong.

Note: After enabling the package, you usually have to restart / reload services so that the newly enabled module is recognized. For apache, you can do this by:

sudo service apache2 restart

If you do not use apache, please use the equivalent command for your server.

Can't get LDAP functions to load in PHP

You write:

When attempting to use ldap_connect(), I get this error:

Fatal error: Call to undefined function ldap_connect()

You get this error because the function ldap_connect­Docs is not defined. You can not call an undefined function in PHP, that's why you see the fatal error.

To get that function defined, you need to load a PHP module/extension called LDAP. It comes with installation intructions. You wrote:

I've recompiled php with the LDAP apache module enabled.

If you recompile PHP, ensure you enable LDAP, see:

You will need to use the --with-ldap[=DIR] configuration option when compiling PHP to enable LDAP support. DIR is the LDAP base install directory.

However, normally it's enough to just install what you need via the package manager, e.g. try:

# yum install php-ldap

If it's not enough and you actually need to edit your PHP configuration (not always necessary), do it:

$ vi /etc/php.ini

add extension=ldap.so

# service httpd restart

I hope this is helpful. Take care that .dll is windows only.



Related Topics



Leave a reply



Submit