I installed the LDAP development headers:

apt-get install libldb-dev

This added a few ldap headers:

root@crunchbang:/usr/include# ls -la ldap*
-rw-r--r-- 1 root root  9466 Apr 23  2013 ldap_cdefs.h
-rw-r--r-- 1 root root  1814 Apr 23  2013 ldap_features.h
-rw-r--r-- 1 root root 65213 Apr 23  2013 ldap.h
-rw-r--r-- 1 root root  9450 Apr 23  2013 ldap_schema.h
-rw-r--r-- 1 root root  3468 Apr 23  2013 ldap_utf8.h

When I configure and reference the directory:

./configure --with-ldap=/usr/include

I get this error:

checking for LDAP support... yes
checking for LDAP Cyrus SASL support... no
checking size of long int... 4
configure: error: Cannot find ldap libraries in /usr/include.
  • 1
    How is a question about compiling PHP off-topic for server fault? Are no less than FIVE moderators truly unaware that PHP is a ubiquitous "information technology system used in business environments" and that IT professionals are commonly tasked with managing it? Do they not realize that compiling server software is a bread-and-butter System Administration task? There is no valid reason to close this question and it being "off topic" is just flat-out absurd.
    – Goladus
    Oct 15, 2019 at 0:46
  • @Goladus Thank you! Yes. Not sure how this is NOT server related. Oct 15, 2019 at 11:14

6 Answers 6


I ran into this issue trying to get PHP extensions involved in a Docker container. Here is what I had to do:

  1. apt-get install libldb-dev libldap2-dev
  2. ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so \ && ln -s /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/liblber.so
  • Dockerfile....... RUN apt-get update && apt-get install -y \ libldap2-dev \ libldb-dev \ && ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so \ && ln -s /usr/lib/x86_64-linux-gnu/liblber.so /usr/lib/liblber.so
    – Richard
    Feb 25, 2020 at 20:48

This worked for me perfectly.

Install LDAP libraries:

apt-get install libldb-dev

Create SO linker files:

updatedb --prunepaths=/mnt
cd /usr/lib

if [ ! -L liblber-2.4.so.2 ];
    ln -s "$(locate liblber-2.4.so.2)"

if [ ! -L liblber-2.4.so.2.8.3 ];
    ln -s "$(locate liblber-2.4.so.2.8.3)"

if [ ! -L liblber.so ];
    ln -s "$(locate liblber.so)"

if [ ! -L libldap.so ];
    ln -s "$(locate libldap.so)"

if [ ! -L libldap_r.so ];
    ln -s "$(locate libldap_r.so)"

Configure PHP:

./configure --with-ldap=/usr

  • Thanks for the answer. For Ubuntu Trusty, after installing libldb-dev, the following is sufficient: sudo ln -s /usr/lib/i386-linux-gnu/liblber.so /usr/lib, sudo ln -s /usr/lib/i386-linux-gnu/libldap.so /usr/lib.
    – Wtower
    Mar 21, 2016 at 11:09
  • Also, make sure you are not specifying lib64 libraries path as that is a sure-fire way of making sure compilation fails. This is the actual fix! --with-libdir=lib64 \ //This is what I am referring to
    – prog_24
    Mar 31, 2016 at 12:54

The cleanest way to do it, according to this comment in the issues of the official PHP Docker image, is using libldap2-dev (in Debian/Ubuntu) and calling configure with --with-libdir=lib/x86_64-linux-gnu.


PHP Version 5.6.20 debian and based: su aptitude install libldb-dev ln -s /usr/lib/x86_64-linux-gnu/libldap.so /usr/lib/libldap.so then, try to compile it


I had this same issue and none of the answers above helped. Then after some digging into PHP's configure file I found a different solution.

1) Check which lib directoriy you are using. If you use the switch --with-libdir=lib64 then you should have the libldap.so and the other .so files in /usr/lib64. If you are not specifying a libdir then the .so files should be in /usr/lib. You can create symlinks if the .so file are in a non-standard directory (like /usr/lib64) but you dont want to specify the libdir.

2) Use the switch --with-ldap=yes

I wonder why this is not documented in the configure help.

  • For me --with-ldap=yes found.
    – Iago Leão
    Nov 27, 2018 at 0:24

(Assuming you're on Ubuntu) Please try configure --with-ldap-libs=/usr/lib/i386-linux-gnu/. If doesn't help, please extend your answer with details on which Linux distro do you use and which project you're building.

  • Tried it. Doesn't work. configure: error: Cannot find ldap libraries in /usr/lib. Oct 3, 2014 at 17:58
  • Updated the answer. Please follow-up.
    – yrk
    Oct 3, 2014 at 18:02
  • I don't think --with-ldap-libs is an option. I've tried --with-ldap-dir and it seemed to work but when I tried to use a php ldap function it didn't work. Oct 3, 2014 at 19:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.