Search code examples
phpapacheredhatopenldap

Can't get LDAP functions to load in PHP


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

Fatal error: Call to undefined function ldap_connect()

I've recompiled php with the LDAP apache module enabled, and I've edited my php.ini file, too and uncommented:

extension=php_ldap.dll

I'm on Red Hat Linux, php 5.3.10, apache 2.2. Any ideas?

Loaded Apache Modules: (contains *util_ldap*)

core mod_authn_file mod_authn_default mod_authz_host mod_authz_groupfile mod_authz_user mod_authz_default mod_auth_basic mod_include mod_filter util_ldap mod_log_config mod_logio mod_env mod_expires mod_headers mod_setenvif mod_version mod_proxy mod_proxy_connect mod_proxy_ftp mod_proxy_http mod_proxy_scgi mod_proxy_ajp mod_proxy_balancer mod_ssl prefork http_core mod_mime mod_status mod_autoindex mod_asis mod_info mod_suexec mod_cgi mod_negotiation mod_dir mod_actions mod_userdir mod_alias mod_rewrite mod_so mod_auth_passthrough mod_bwlimited mod_fpcgid mod_php5 mod_security

Apache Protocols: (contains: ldap)

dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, smtp, smtps, telnet, tftp


Solution

  • 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.