skip to Main Content

I am running a Debian Linux server that is hosting my Apache2 web server for an in-house web application I am developing. I am attempting to utilize LDAP for user authentication by communicating with our Active Directory server checking user info and global security groups.

On my Linux server I installed the php_ldap module using the standard apt-get:

sudo apt-get install php-ldap

I then modified my php.ini file to uncomment this extension:

extension=ldap

And add this extension:

extension=php_ldap.so

I have not altered my apache2.conf file yet as in my dev environment (which is unfortunately in Windows for now due to various constraints I’ve picked up from previous developers) the current setup works.

Besides installing the module, and enabling it in my configuration files, then lastly restarting the apache2 service on my linux server, I’m not sure what else I could be missing.

When I attempt to POST to my index.php page with the login information I get a this error:

PHP Fatal error: Uncaught Error: Call to undefined function ldap_connect()...

It is obviously not recognizing the LDAP methods I’ve implemented but for the life of me I cannot figure out why. All the googling I’ve done has led me to the same exact steps I’ve already outlined so if anyone has any additional information that could help me out I’d greatly appreciate it.

2

Answers


  1. You can easily install LDAP if you are using Docker.

    If you don’t then I would like to encourage you to start using it. Docker works on Linux and Windows as well.

    How to install Docker

    Then create a text file called Dockerfile

    FROM php:7.4-apache
    RUN apt-get update -y --fix-missing && apt-get upgrade -y
    RUN apt-get install -y libldb-dev libldap2-dev && docker-php-ext-install -j$(nproc) ldap
    

    in the same directory where is Dockerfile issue a command:

    docker build -t my-php .
    

    to see build images:

    docker image ls
    

    to run the image and enter shell type:

    docker run --rm -it my-php:7.4-apache /bin/bash
    

    once you are into shell type:

    php -m
    

    and you should see list of extensions including ldap.

    type into shell

    exit
    

    to leave it

    and you may start your web server with the command:

    docker run -d -p 80:80 --name my-php-apache -v "path/to/web/dir/on/local/machine":/var/www/html php:7.4-apache
    

    How to use apache docker image – look for the section php:<version>-apache

    If you would like to install also other extensions see the section How to install more PHP extensions

    There are also other useful Docker images like MySQL that you may want to use as well.

    Login or Signup to reply.
  2. First check phpinfo(). When PHP had not been built with flags --with-ldap or --with-ldap-sasl, you’ll have to build PHP from source, in order to get LDAP support with or without SASL.

    In case it had been enabled at build time, then package php7.0-ldap should suffice. Run dpkg -L php7.0-ldap to see what and where it installs. If anything else may be required, then this may be php -m and phpenmod ldap.

    One can apply LDAP configuration with a /home/www-data/.ldaprc file:
    https://manpages.ubuntu.com/manpages/cosmic/man5/ldap.conf.5.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search