You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:PHP通过Microsoft Entra Domain Services的LDAPS绑定Azure AD失败

LDAPS连接Microsoft Entra Domain Services绑定失败问题

背景

已为Azure Active Directory启用Microsoft Entra Domain Services的Secure LDAP(LDAPS),该服务在其他应用中运行正常,确认已启用且可用。现尝试构建PHP应用获取Azure AD中的所有用户列表,参考PHP官方文档的ldap_bind函数开发,但对LDAP不熟悉。

可成功运行的连接代码

$ldapconn = ldap_connect("ldaps://ds.example.co.uk")
          or die("Could not connect to LDAP server.");

匿名绑定失败

代码

$ldapconn = ldap_connect("ldaps://ds.example.co.uk")
    or die("Could not connect to LDAP server.");

if ($ldapconn) {

    // 匿名绑定
    $ldapbind = ldap_bind($ldapconn);

    if ($ldapbind) {
        echo "LDAP匿名绑定成功...";
    } else {
        echo "LDAP匿名绑定失败...";
    }

}

报错信息

Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in /ldap.php on line ##

LDAP匿名绑定失败...

错误发生在代码行:$ldapbind = ldap_bind($ldapconn);

使用凭证绑定失败

代码

// 使用LDAP绑定
$ldaprdn  = 'firstname.lastname@example.co.uk';     // LDAP RDN或DN
$ldappass = 'passwordexample123!';  // 对应密码

// 连接LDAP服务器
$ldapconn = ldap_connect("ldaps://ds.example.co.uk")
    or die("Could not connect to LDAP server.");

if ($ldapconn) {

    // 绑定到LDAP服务器
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

    // 验证绑定结果
    if ($ldapbind) {
        echo "LDAP绑定成功...";
    } else {
        echo "LDAP绑定失败...";
    }

}

报错信息

Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in /ldap.php on line ##

LDAP绑定失败...

错误发生在代码行:$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);

请求建议

  • A) 如何排查该问题?比如查看Entra日志或服务器日志?(目前控制台无相关记录)
  • B) 代码是否存在明显语法错误?根据官方文档,OU应为默认的AADDC Users,但不清楚如何在代码中正确使用它。

内容的提问来源于stack exchange,提问作者Henry Aspden

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 18:25:13