下载openldap2.2.29.rar,并一路next下去。

然后根据网上配置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服务地址
    $ldap_host = "ldap://127.0.0.1";
    //ldap服务占用端口
    $ldap_port = 389;
    //链接ldap服务器
    $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) ;//or die("Can not binding to LDAP server.");
 
    var_dump($ldap_conn);

?>

但提示:

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Protocol error in D:\virtual\test.php on line 14
resource(2) of type (ldap link)

于是又在网上找到解决办法:

在slapd.conf 最后加一句:allow bind_v2

原因(据openldap官网):

OpenLDAP Software does not support LDAPv2 (now historic). OpenLDAP 2.x's slapd(8) can be configured to accept a version 2 LDAP Bind request, but expects requesting version 2 to speak a restricted, non-standard variant for LDAPv3 (basically LDAPv3 syntaxes and semantics in LDAPv2 PDUs). To enable this, place the following in your slapd.conf(5) file.

照着加入了后重启OpenLDAP Directory Service后,就正常了。