LDAP 可与 PHP CLI 配合使用,但不能通过 apache 配合使用
我正在尝试从 Fedora 机器通过 LDAP 对 Windows 2008 Server 进行身份验证。
以下代码在命令行中运行(打印“成功”):
if($ldap = ldap_connect('10.0.0.101'))
{
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
$bind = ldap_bind($ldap,'[email protected]','XXXXXXX');
print ldap_error($ldap);
}
...通过 Apache/mod_php 拉取同一文件打印“无法联系 LDAP 服务器”
我已经看到很多此类问题的报告,但没有有关如何解决该问题的有用信息。
I'm trying to authenticate over LDAP against a Windows 2008 Server from a Fedora box.
The following code works from the command line (prints "Success"):
if($ldap = ldap_connect('10.0.0.101'))
{
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
$bind = ldap_bind($ldap,'[email protected]','XXXXXXX');
print ldap_error($ldap);
}
...pulling the same file via Apache/mod_php prints "Can't contact LDAP server"
I've seen a lot of reports of issues like this, but no useful information on how to resolve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是在 centos6 上与这个问题斗争了很长时间。 php.ini 的差异似乎是一个检查的好地方,但它没有给我答案。原来这和SELinux有关。
您会注意到,在我的例子中,httpd_can_network_connect 被设置为关闭。这是 SELinux 中的布尔值,可以使用以下命令进行调整。
您可以在 http://wiki.centos.org/TipsAndTricks/SelinuxBooleans 阅读更多相关信息,其中明确使用了以下情况以 apache 和 ldap 为例。希望有帮助!
I just fought this exact problem for a long time on centos6. The php.ini difference seem like a good place to check, but it didn't give me the answer. It turns out this was related to SELinux.
You'll note, that in my case, httpd_can_network_connect was set to off. This is a boolean in SELinux and can be adjusted with the following command.
You can read more about this at http://wiki.centos.org/TipsAndTricks/SelinuxBooleans which explicitly uses the case of apache and ldap as an example. Hope it helps!
您可能会遇到此问题,因为 Apache 有一个
php.ini
文件,而CLI
可能有另一个文件,并且 Apache 版本可能没有LDAP
扩展名已启用。尝试使用
phpinfo( 来检查正在加载的
在您的两个环境中:php.ini
)您应该看到
php.ini
的路径和其他有用信息:查看
CLI 上加载的配置的替代方法
是通过调用php
来实现的-i
参数:You might be having this problem because Apache has one
php.ini
file andCLI
might have another, and the Apache version might not haveLDAP
extension enabled.Try checking which
php.ini
is loading withphpinfo()
in both of your environments:You should see the path of
php.ini
and additional useful information:An alternative method to see the configuration loaded on the
CLI
is by callingphp
with-i
parameter: