Can't get LDAP functions to load in PHP

孤街醉人 提交于 2019-12-08 01:30:33

问题


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


回答1:


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.




回答2:


I would strongly recommend you use the PHP that you can install using yum. Depending on your RH version, you may have to specify that you want php53 (for RH < 6). So, do the install like this:

  1. yum install php53
  2. yum install php53-ldap

At this point, you should be good to go. You do not need to have any special Apache LDAP library installed at all to get PHP to work with LDAP.

If you are using RH 6, then you can skip the 53 part of the name.




回答3:


This is mostly a hunch, but have you tried downgrading to PHP 5.3.9?

There's a small amount of buzz on the internet about LDAP being broken on 5.3.10. Also, could try PHP 5.4 if you felt daring.




回答4:


For CentOs. I have installed Php 7. So when I tried to execute

yum install php-ldap

there was this error

php71w-common conflicts with php-common-5.4.16-43.el7_4.1.x86_64

To solve this error and install ldap-php, execute

yum install php71w-ldap

The server will be trying to install 5.6 But we need to guide the server to install with 7.

If it is not working try adding the extension in php.ini which is mentioned in the other answer.

And don't forgot to restart the server.

Once the installation is done, the ldap-login will be done successfully.



来源:https://stackoverflow.com/questions/10078205/cant-get-ldap-functions-to-load-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!