PHPackages                             ldaptools/ldaptools - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ldaptools/ldaptools

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ldaptools/ldaptools
===================

LdapTools is a feature-rich LDAP library for PHP 5.6+.

v0.25.2(8y ago)204263.9k↑16.5%44[22 issues](https://github.com/ldaptools/ldaptools/issues)[7 PRs](https://github.com/ldaptools/ldaptools/pulls)1MITPHPPHP &gt;=5.6

Since Jan 31Pushed 3y ago12 watchersCompare

[ Source](https://github.com/ldaptools/ldaptools)[ Packagist](https://packagist.org/packages/ldaptools/ldaptools)[ Docs](http://www.phpldaptools.com)[ RSS](/packages/ldaptools-ldaptools/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (24)Used By (1)

LdapTools [![Build Status](https://camo.githubusercontent.com/08365e29add244ede3d69fa79981c3dfdfa7918515a5ec7cf37875590990a7c2/68747470733a2f2f7472617669732d63692e6f72672f6c646170746f6f6c732f6c646170746f6f6c732e737667)](https://travis-ci.org/ldaptools/ldaptools) [![AppVeyor Build Status](https://camo.githubusercontent.com/c5f92d767dabe2b5819b292f2f9dccb0c62718498307e1223062aed25e1fc869/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f6769746875622f6c646170746f6f6c732f6c646170746f6f6c733f6272616e63683d6d6173746572267376673d74727565)](https://ci.appveyor.com/project/ChadSikorra/ldaptools) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/20d3644de423010969f7cd7a2251cd8f59d0df86418249842e8187ea38172057/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c646170746f6f6c732f6c646170746f6f6c732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ldaptools/ldaptools/?branch=master) [![Latest Stable Version](https://camo.githubusercontent.com/866f677e02cee327d550a40dbdc1b58fe9fda8c711c6516dba1ac0b035956cf4/68747470733a2f2f706f7365722e707567782e6f72672f6c646170746f6f6c732f6c646170746f6f6c732f762f737461626c652e737667)](https://packagist.org/packages/ldaptools/ldaptools)
====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#ldaptools----)

---

LdapTools is a feature-rich LDAP library for PHP 5.6+. It was designed to be customizable for use with pretty much any directory service, but contains default attribute converters and schemas for Active Directory and OpenLDAP.

- A fluent and easy to understand syntax for [generating LDAP queries](#searching-ldap).
- Easily [create](#creating-ldap-objects)/[modify](#modifying-ldap-objects)/[delete](#deleting-ldap-objects)/[restore](/docs/en/tutorials/Using-the-LDAP-Manager.md#restoring-ldap-objects) common LDAP objects (Users, Groups, Contacts, Computers, OUs).
- Retrieve LDAP objects as either a simple array or an object with automagic setters/getters.
- A [logging mechanism](/docs/en/reference/Logging.md) for all LDAP operations
- An [event system](/docs/en/reference/Events.md) for further customization, extensibility, and integration.
- Parse and create [LDIF files](/docs/en/tutorials/LDIF-Files.md).
- View and modify [Active Directory permissions](/docs/en/tutorials/AD-Permissions.md).

### Installation

[](#installation)

The recommended way to install LdapTools is using [Composer](http://getcomposer.org/download/):

```
composer require ldaptools/ldaptools
```

### Getting Started

[](#getting-started)

The easiest way to get started is by creating a YAML config file. See the [example config](resources/config/example.yml) file for basic usage. See the [configuration file reference doc](/docs/en/reference/Main-Configuration.md) for a list of all available options.

Once you have a configuration file defined, you can get up and running by doing the following:

```
use LdapTools\Configuration;
use LdapTools\LdapManager;

$config = (new Configuration())->load('/path/to/ldap/config.yml');
$ldap = new LdapManager($config);
```

### Searching LDAP

[](#searching-ldap)

With the `LdapManager` up and going you can now easily build LDAP queries without having to remember all the special syntax for LDAP filters. All values are also automatically escaped. Check the [tutorial](/docs/en/tutorials/Building-LDAP-Queries.md) for all available methods and the [cookbook](/docs/en/cookbook/Common-LDAP-Queries.md) for more query examples.

```
use LdapTools\Object\LdapObjectType;

// Get an instance of the query...
$query = $ldap->buildLdapQuery();

// Returns a LdapObjectCollection of all users whose first name
// starts with 'Foo' and last name is 'Bar' or 'Smith'.
// The result set will also be ordered by state name (ascending).
$users = $query->fromUsers()
    ->where($query->filter()->startsWith('firstName', 'Foo'))
    ->orWhere(['lastName' => 'Bar'])
    ->orWhere(['lastName' => 'Smith'])
    ->orderBy('state')
    ->getLdapQuery()
    ->getResult();

echo "Found ".$users->count()." user(s).";
foreach ($users as $user) {
    echo "User: ".$user->getUsername();
}

// Get all OUs and Containers at the base of the domain, ordered by name.
$results = $ldap->buildLdapQuery()
    ->from(LdapObjectType::OU)
    ->from(LdapObjectType::CONTAINER)
    ->orderBy('name')
    ->setScopeOneLevel()
    ->getLdapQuery()
    ->getResult();

// Get a single LDAP object and select some specific attributes...
$user = $ldap->buildLdapQuery()
    ->select(['upn', 'guid', 'sid', 'passwordLastSet'])
    ->fromUsers()
    ->where(['username' => 'chad'])
    ->getLdapQuery()
    ->getSingleResult();

// Get a single attribute value from a LDAP object...
$guid = $ldap->buildLdapQuery()
    ->select('guid')
    ->fromUsers()
    ->where(['username' => 'chad'])
    ->getLdapQuery()
    ->getSingleScalarResult();

// It also supports the concepts of repositories...
$userRepository = $ldap->getRepository('user');

// Find all users whose last name equals Smith.
$users = $userRepository->findByLastName('Smith');

// Get the first user whose username equals 'jsmith'. Returns a `LdapObject`.
$user = $userRepository->findOneByUsername('jsmith');
echo "First name ".$user->getFirstName()." and last name ".$user->getLastName();
```

See [the docs](/docs/en/tutorials/Building-LDAP-Queries.md) for more information on building LDAP queries.

### Modifying LDAP Objects

[](#modifying-ldap-objects)

Modifying LDAP is as easy as searching for the LDAP object as described above, then making changes directly to the object and saving it back to LDAP using the `LdapManager`.

```
$user = $ldap->buildLdapQuery()
    ->select(['title', 'mobilePhone', 'disabled'])
    ->fromUsers()
    ->where(['username' => 'jsmith'])
    ->getLdapQuery()
    ->getSingleResult();

// Make some modifications to the user account.
// All these changes are tracked so it knows how to modify the object.
$user->setTitle('CEO');

if ($user->hasMobilePhone()) {
    $user->resetMobilePhone();
}

// Set a field by a property instead...
if ($user->disabled) {
    $user->disabled = false;
}

// Add a value to an attribute...
$user->addOtherIpPhones('#001-5555');
// Add a few values at one time...
$user->addOtherIpPhones('#001-4444', '#001-3333', '#001-2222');

// Now actually save the changes back to LDAP...
try {
    $ldap->persist($user);
} catch (\Exception $e) {
    echo "Error updating user! ".$e->getMessage();
}
```

See [the docs](/docs/en/tutorials/Modifying-LDAP-Objects.md) for more information on modifying LDAP objects.

### Deleting LDAP Objects

[](#deleting-ldap-objects)

Deleting LDAP objects is a simple matter of searching for the object you want to remove, then passing it to the delete method on the `LdapManager`:

```
// Decide they no longer work here and should be deleted?
$user = $userRepository->findOneByUsername('jsmith');

try {
    $ldap->delete($user);
} catch (\Exception $e) {
    echo "Error deleting user! ".$e->getMessage();
}
```

### Creating LDAP Objects

[](#creating-ldap-objects)

Creating LDAP objects is easily performed by just passing what you want the attributes to be and what container/OU the object should end up in:

```
$ldapObject = $ldap->createLdapObject();

// Creating a user account (enabled by default)
$ldapObject->createUser()
    ->in('cn=Users,dc=example,dc=local')
    ->with(['username' => 'jsmith', 'password' => '12345'])
    ->execute();

// Create a typical AD global security group...
$ldapObject->createGroup()
    ->in('dc=example,dc=local')
    ->with(['name' => 'Generic Security Group'])
    ->execute();

// Creates a contact user...
$ldapObject->createContact()
    ->in('dc=example,dc=local')
    ->with(['name' => 'Some Guy', 'emailAddress' => 'SomeGuy@SomeDomain.com'])
    ->execute();

// Creates a computer object...
$ldapObject->createComputer()
    ->in('dc=example,dc=local')
    ->with(['name' => 'MYWOKRSTATION'])
    ->execute();

// Creates an OU object...
$ldapObject->createOU()
    ->in('dc=example,dc=local')
    ->with(['name' => 'Employees'])
    ->execute();
```

See [the docs](/docs/en/tutorials/Creating-LDAP-Objects.md) for more information on creating LDAP objects.

### Documentation

[](#documentation)

Browse [the docs folder](/docs/en) for more information about LdapTools.

- [Main Configuration Reference](/docs/en/reference/Main-Configuration.md)
- [Schema Configuration](/docs/en/reference/Schema-Configuration.md)
- [Using the LdapManager](/docs/en/tutorials/Using-the-LDAP-Manager.md)
- [Building LDAP Queries](/docs/en/tutorials/Building-LDAP-Queries.md)
- [Creating LDAP Objects](/docs/en/tutorials/Creating-LDAP-Objects.md)
- [Modifying LDAP Objects](/docs/en/tutorials/Modifying-LDAP-Objects.md)
- [LDIF files](/docs/en/tutorials/LDIF-Files.md)
- [Active Directory Permissions](/docs/en/tutorials/AD-Permissions.md)
- [Creating Exchange Mailboxes](/docs/en/cookbook/Creating-Exchange-Mailboxes.md)
- [Default Schema Attributes](/docs/en/reference/Default-Schema-Attributes.md)
- [The Event System](/docs/en/reference/Events.md)

### TODO

[](#todo)

Things that still need to be implemented:

- Automatic generation of the schema based off of information in LDAP.
- More work needed on the OpenLDAP schema.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity52

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~45 days

Recently: every ~85 days

Total

23

Last Release

3117d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/388229?v=4)[Chad Sikorra](/maintainers/ChadSikorra)[@ChadSikorra](https://github.com/ChadSikorra)

---

Top Contributors

[![ChadSikorra](https://avatars.githubusercontent.com/u/388229?v=4)](https://github.com/ChadSikorra "ChadSikorra (824 commits)")[![markusu49](https://avatars.githubusercontent.com/u/25197418?v=4)](https://github.com/markusu49 "markusu49 (2 commits)")[![MarcoRemy](https://avatars.githubusercontent.com/u/7585335?v=4)](https://github.com/MarcoRemy "MarcoRemy (1 commits)")

---

Tags

active-directoryexchangeldapphp-ldapldapactive directoryopenldapMicrosoft Exchange

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/ldaptools-ldaptools/health.svg)

```
[![Health](https://phpackages.com/badges/ldaptools-ldaptools/health.svg)](https://phpackages.com/packages/ldaptools-ldaptools)
```

###  Alternatives

[symfony/ldap

Provides a LDAP client for PHP on top of PHP's ldap extension

1407.5M46](/packages/symfony-ldap)[freedsx/ldap

A Pure PHP LDAP library

157142.4k2](/packages/freedsx-ldap)[ldaptools/ldaptools-bundle

Provides easy LDAP integration for Symfony via LdapTools.

49159.5k](/packages/ldaptools-ldaptools-bundle)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[avadaneidanut/ldapquery

A light weight package for easily building LDAP advanced filter queries.

4717.8k](/packages/avadaneidanut-ldapquery)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
