Adding LDAP to PHP on DreamHost

Submitted by Darren Oh on

I have been a DreamHost customer since 2006. I love the affordability and flexibility of their shared hosting. DreamHost allows customers to compile custom PHP extensions on shared hosting. I used this to add LDAP support to PHP. This worked fine until DreamHost upgraded their shared hosting servers to Ubuntu 22.04.

The PHP extension I had compiled did not work with the new LDAP library. I could have easily compiled the extension again, but for some reason DreamHost neglected to include the LDAP library header files in the upgraded servers. Thanks to instructions from DreamHost customer service and some help from Google AI, I was able to work around the problem without waiting for DreamHost to fix it. Here is a step by step guide.

  1. Download .deb packages for LDAP libraries and headers.

    apt download libldap-2.5-0 libldap-dev libsasl2-2 libsasl2-dev

  2. Unpack the packages and headers in your home directory.

    for f in *.deb; do dpkg -x "$f" .; done

  3. Clean up the package files.

    rm *.deb

  4. Set the config path.

    export PKG_CONFIG_PATH=$HOME/usr/lib/x86_64-linux-gnu/pkgconfig

  5. You can now follow the instructions for compiling PHP extensions. The LDAP extension is part of the PHP source code, so download the PHP release matching the DreamHost PHP version you want to use. To see the PHP 8.4 version, run

    php-8.4 -v

  6. When you configure, you will need to provide the library directories. For PHP 8.4,

    ./configure --with-php-config=/usr/local/php84/bin/php-config --with-ldap=$HOME/usr --with-ldap-sasl=$HOME/usr --with-libdir=lib/x86_64-linux-gnu

The drawback to this workaround is that library files in your home directory do not get DreamHost security updates. Maybe you could fix that by replacing them with symlinks to the system library files. I hope DreamHost fixes the missing header files soon.