---
name: yii2-ldap
description: Configure and verify Yii2 LDAP directories with yii2-extensions/ldap. Use for named LdapRecord connections, user synchronization, direct group membership, and optional password verification.
license: BSD-3-Clause
---

# LDAP directories for Yii2

Check the installed versions of `yii2-extensions/ldap`, `yiisoft/yii2`, and `directorytree/ldaprecord`. Verify the
application's PHP runtime loads `ext-ldap`. Use the installed PHPDoc and the matching
[package guides](https://github.com/yii2-extensions/ldap/tree/main/docs); the default branch may be newer than the
installed package.

- Bootstrap `yii2\extensions\ldap\Directory` with named service connections. Use the matching OpenLDAP or Active
  Directory LdapRecord models and select the connection by name. Every connection uses StartTLS on the plain LDAP port,
  validates the server certificate and does not follow referrals; no setting changes this, LDAPS is not supported, and
  unknown endpoint keys are ignored. Fix a TLS failure in the LDAP client's CA trust, not by weakening validation. Keep
  credentials out of configuration committed to Git and out of diagnostic output.
- Give read and write connections separate accounts and LDAP permissions. Set `writable` only on the connection that
  should change group membership. Load both persisted models on that connection before using `setMembership()`. It
  changes one direct membership, not a primary group or a nested group.
- Use `UserSynchronizer` on a named read connection. Map attributes explicitly and key the application's upsert by the
  connection name and stable identifier, not the username or DN. A failed run may leave earlier upserts committed; it
  must not be used as evidence that missing users should be removed.
- Use `PasswordVerifier` only when the application checks the password itself. Resolve the bind principal from the
  application's trusted identity mapping. Treat a rejected password and `DirectoryUnavailableException` as distinct
  outcomes internally. Authentication sessions and authorization belong to the application.
- For persistent workers, distinguish `disconnect()` (close handles) from `unregister()` (also release the component's
  names). Check the configuration guide before choosing the lifecycle hook.

Verify changes against a disposable directory of the same schema. Check that reads and writes use the intended accounts
and that paging preserves all rows. An OpenLDAP test does not establish Active Directory compatibility.
