Syncing LDAP (OD or AD) data within Moodle

So we have a Moodle server at our school that is connected to our LDAP server for user authentication.  This works great for us as it provides for easy integration with out other systems that use this form of authentication (FinalSite web site / WebHelpDesk/Apple ODstructure).

One issue we had though was that certain data was being entered at the time of user creation and other fields we just left blank.  This was fine until we needed to get information out of Moodle and into our school’s information system (SIS), particularly student emails.

The issue was that while the Moodle database has an ID for each user this ID didn’t match anything in our SIS or LDAP directory (Apple OD).  The ID assigned to students in the LDAP/OD system is based on one generated in or SIS… so we needed to get that ID into Moodle.

I was able to map the correct field from LDAP (uidNumber) to the ID Number field in Moodle and set the “Update local” bit to “On every login”, but this would only update the ID on the next user login and I needed to have it sooner.

What I needed to do was to run a sync of the Moodle database to the LDAP server to have this newly mapped value brought into the system… but how to do that.

Here you go:

  1. Via Terminal navigate to /var/www/html/auth/ldap
  2. You will need to run  “auth_ldap_sync_users.php”. This script must be run in this manner.

This will add any users entered in LDAP that are not already in the Moodle system (WARNING: You may get users from LDAP you don’t want in Moodle). It will also add any of the newly mapped attributes to those users already in the system.

This simple process saved me a TON of work… hopefully it will help you too.



About William Stites

Currently the Director of Technology for Montclair Kimberley Academy, "Blogger in Chief" for, husband and father to two crazy kids who make me smile everyday.
This entry was posted in EdTech, Moodle, Technical and tagged , , , , , . Bookmark the permalink.
  • Anisorf

    Hi, i’m trying to find some help on one of my problems. We have drupal7 site like a front-end informational portal, and moodle2 site like back-end  we use CAS for SingleSignOn between drupal and moodle and we use LDAP for authorization. We are still in the process of making the LDAP Directory Tree where will have information for every user(student/teacher/teacher of a teacher) and information for the moodle corses.
    The authentication till now is working more or less fine.
    But my concern is:
    1. the authorization which i was thinking to make it with Access Control List , and i hope that with using the moodle – ldap enrolments all the users will have the rights deffined from ldap and nothing more.
    2. I need to make ldap query(search, modify…), for the different courses or query on the students etc but from moodle…is this possible?how can i make moodle to be client for this queries for the ldap-server?

    Thanks in advance, any help will be appreciate.
    P.S. sorry for my english:)