During the testing or development times there may be chances when you might have accidentally lost access to your admin account and couldn’t reset it without any means like no forget password (which may not be working on localhost).
It may happen while working around with roles where tempering with admin role will result in no admin account for the site like it happened with Pedro Cruz.
Ken Task as usual comes with his ‘Spirit of Sharing’ with another very great and useful tip through which you can assign admin role to any user without any changes in the database, nothing to restart. All you need to know is the user ID of the account and then you can directly login with that user account in a normal way.
To assign the admin role to any user all you need to change is to add a single line of code in your config.php file and save it. Just add the following:

Post Pages - Post Inline - WIRIS
$CFG->siteadmins='2,[yourotheradminid]';

where 2 is the original admin user established when first installing, and [yourotheradminid] the ID number of the other user you setup as admin levels. The ID number of the other user can be checked in the database table mdl_user (where mdl is your database prefix).
Here is a snapshot of my development Moodle database user table to show where to check out for the ID of a user.Admin RoleAfter adding the line of code to my config.php file, when I logged in with the standard student account, I was having all admin account priviledges and then I again reset my normal admin account.
Hope this tip also helps you in case of any such emergency. Do you any other tips and tricks which can be helpful in cases of disaster like this? If yes, please share with us in the comments below.
Reference: https://moodle.org/mod/forum/discuss.php?d=324918

Previous articleUpdated For 3.0: Socialwall Course Format
Next articleLet Students Choose With The Group Choice Plugin

5 COMMENTS

  1. This doesn’t seem to fix my issue, I cant find any updated articles/forums on this. Does anyone have any ideas?

  2. Hi Paula, did you lose admin access to your Moodle site? That’s never fun 😪
    The solutions are usually variations on the following:
    1. Ask another admin to restore your account or reset your password
    2. Accessing the Moodle config files and editing the roles and permission. It appears Moodle has not added much info here that is not on the article. But you can also check https://docs.moodle.org/dev/Role_archetypes#Admins_without_a_role

    I think worst case scenario is to backup the MoodleData files (courses, users, enrollments), erase and set up a whole new Moodle site, then import the data. Of course, that’s a last measure step and will definitely come with headaches. I advise you get expert help before proceeding.

    Good luck! Let me know how it goes 🙂

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.