Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Windows 綜合教學 >> 關於 Windows

Windows 下安裝 OpenLDAP 2.2.29 並解決 PHP ldap_bind 協定錯誤教學

編輯:關於 Windows

在 Windows 環境安裝 OpenLDAP 2.2.29 後,使用 PHP 測試連線時遇到 ldap_bind(): Unable to bind to server: Protocol error。經查證為 OpenLDAP 2.x 預設不支援 LDAPv2 協定,需在 slapd.conf 加入 allow bind_v2 才能相容舊版用戶端。本文記錄完整安裝設定與除錯過程。

安裝與基本設定

  1. 下載 openldap-2.2.29 安裝檔,一路「下一步」完成安裝。
  2. 編輯 slapd.conf,在 include ./schema/core.schema 後加入:
include ./schema/cosine.schema
include ./schema/inetorgperson.schema
include ./schema/nis.schema
include ./schema/misc.schema

PHP 測試程式碼

<?php
$ldap_host = "ldap://127.0.0.1";
$ldap_port = 389;
$ldap_conn = ldap_connect($ldap_host, $ldap_port) or die("Can not connect LDAP server.");

$rootdn = 'cn=Manager,dc=my-domain,dc=com';
$rootpw = 'secret';
ldap_bind($ldap_conn, $rootdn, $rootpw);
var_dump($ldap_conn);
?>

錯誤與解決

執行後出現:Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Protocol error。根據 OpenLDAP 官方文件,2.x 版預設停用 LDAPv2,需在 slapd.conf 末尾加入:

allow bind_v2

重啟「OpenLDAP Directory Service」服務後,PHP 測試即可正常綁定並回傳 resource 物件。

說明:OpenLDAP 2.x 允許接受 LDAPv2 Bind 請求,但要求用戶端使用受限的非標準 LDAPv3 變體。啟用 allow bind_v2 即可相容舊版 PHP LDAP 擴充套件。

Copyright © Windows教程網 All Rights Reserved