无法在 PHP 中加载 LDAP 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10078205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 21:20:04  来源:igfitidea点击:

Can't get LDAP functions to load in PHP

phpapacheredhatopenldap

提问by Citizen

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

尝试使用时ldap_connect(),我收到此错误:

Fatal error: Call to undefined function ldap_connect()

致命错误:调用未定义的函数 ldap_connect()

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

我已经在启用 LDAP apache 模块的情况下重新编译了 php,并且我也编辑了我的 php.ini 文件并且取消了注释:

extension=php_ldap.dll

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

我使用的是 Red Hat Linux,php 5.3.10,apache 2.2。有任何想法吗?

Loaded Apache Modules: (contains *util_ldap*)

加载的 Apache 模块:(包含 *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

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_headers中指定mod_expires 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)

Apache 协议:(包含:ldap

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

dict、文件、ftp、ftps、gopher、http、https、imap、imaps、ldap、ldaps、pop3、pop3s、rtsp、smtp、smtps、telnet、tftp

回答by hakre

You write:

你写:

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

Fatal error: Call to undefined function ldap_connect()

尝试使用 ldap_connect() 时,出现此错误:

致命错误:调用未定义的函数 ldap_connect()

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

您收到此错误是因为未定义函数ldap_connectDocs。您不能在 PHP 中调用未定义的函数,这就是您看到致命错误的原因。

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

要定义该函数,您需要加载一个名为LDAP. 它带有安装说明。你写了:

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

我已经在启用 LDAP apache 模块的情况下重新编译了 php。

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

如果重新编译 PHP,请确保启用 LDAP,请参阅:

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.

--with-ldap[=DIR]在编译 PHP 以启用 LDAP 支持时,您将需要使用配置选项。DIR 是 LDAP 基本安装目录。

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:

如果这还不够,并且您确实需要编辑 PHP 配置(并非总是必要的),请执行以下操作:

$ vi /etc/php.ini

add extension=ldap.so

# service httpd restart

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

我希望这是有帮助的。注意.dll只有窗户。

回答by Thomas Schultz

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

这主要是一种预感,但是您是否尝试过降级到 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.

互联网上有一些关于 LDAP 在 5.3.10 被破坏的嗡嗡声。另外,如果您有胆量,可以尝试 PHP 5.4。

回答by Lucas Rockwell

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:

我强烈建议您使用可以使用 yum 安装的 PHP。根据您的 RH 版本,您可能必须指定您想要 php53(对于 RH < 6)。所以,像这样安装:

  1. yum install php53
  2. yum install php53-ldap
  1. yum 安装 php53
  2. yum 安装 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.

此时,您应该可以开始了。您根本不需要安装任何特殊的 Apache LDAP 库即可让 PHP 与 LDAP 一起工作。

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

如果您使用的是 RH 6,那么您可以跳过名称的 53 部分。

回答by Pravinraj Venkatachalam

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

对于 CentO。我已经安装了 Php 7。所以当我尝试执行时

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

要解决此错误并安装 ldap-php,请执行

yum install php71w-ldap

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

服务器会尝试安装 5.6 但我们需要引导服务器安装 7。

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

如果它不起作用,请尝试在另一个答案中提到的 php.ini 中添加扩展名。

And don't forgot to restart the server.

并且不要忘记重新启动服务器。

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

安装完成后,ldap-login 将成功完成。