php - LDAP 适用于 PHP CLI 但不能通过 apache

标签 php windows ldap

我正在尝试通过 LDAP 对来自 Fedora box 的 Windows 2008 Server 进行身份验证。

以下代码从命令行运行(打印“成功”):

if($ldap = ldap_connect('10.0.0.101'))
{
  ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
  $bind = ldap_bind($ldap,'administrator@domain.tld','XXXXXXX');
  print ldap_error($ldap);
}

...通过 Apache/mod_php 拉取相同的文件打印“无法联系 LDAP 服务器”

我看过很多关于此类问题的报告,但没有关于如何解决它的有用信息。

最佳答案

我刚刚在 centos6 上与这个确切的问题斗争了很长时间。 php.ini 差异似乎是检查的好地方,但它没有给我答案。原来这与 SELinux 有关。

$ getsebool -a | grep httpd
allow_httpd_anon_write --> off
allow_httpd_mod_auth_ntlm_winbind --> off
allow_httpd_mod_auth_pam --> off
allow_httpd_sys_script_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> on
httpd_can_network_memcache --> on
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> on
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_manage_ipa --> off
httpd_read_user_content --> off
httpd_run_stickshift --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_tmp_exec --> off
httpd_tty_comm --> on
httpd_unified --> on
httpd_use_cifs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
httpd_use_openstack --> off
httpd_verify_dns --> off

您会注意到,在我的例子中,httpd_can_network_connect 被设置为关闭。这是 SELinux 中的 bool 值,可以使用以下命令进行调整。

$ setsebool -P httpd_can_network_connect on

您可以在 http://wiki.centos.org/TipsAndTricks/SelinuxBooleans 阅读更多相关信息其中明确使用 apache 和 ldap 的情况作为示例。希望对您有所帮助!

关于php - LDAP 适用于 PHP CLI 但不能通过 apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8291631/

相关文章:

php - 比较 mySQL 中的数据

javascript - 如何使用 ajax 分块上传文件并检查是否失败,重新上传失败的部分。

.net - Windows CNG 自定义 key 存储提供程序

python - 在 Windows 10 上安装 weasyprint 的问题

active-directory - 来自 dmz 的 LDAP 访问失败 : : Information about the domain could not be retrieved (1355)

php - 通过 Regex 查找带有第二个参数的所有函数

Python Windows 无法统计包含无效字符的文件

linux - 将 Linux 集成到 Active Directory - 最佳方法?

python - 使用 flask_ldap3_login 使用 LDAP 进行 Flask 身份验证

php - 可以在 Travis CI 中使用自定义变量吗?