Creating an admin user from phpmyadmin

Creating an admin user from phpmyadmin

by Ismail Fayed -
Number of replies: 6

Hello,

For some reason, I lost my admin user and my account has changed to Manager. I want to either be able to get my full administrator right again or upgrade any other user account into full administrator through phpmyadmin. I use Moodle 3.6.1.

Kindly share any step-by-step for doing that. I tried some older methods which actually broke some permissions so had to restore it several times. I look forward to your help.

Thanks,

Ismail

Average of ratings: -
In reply to Ismail Fayed

Re: Creating an admin user from phpmyadmin

by Ken Task -
Picture of Particularly helpful Moodlers

Before using phpmyadmin and any method to directly manipulate mdl_user table IF ... IF .. you know the user ID number of your account that used to be a site admin, try the following:

Add a line to config.php like this:

$CFG->siteadmins='2,yourID,otherID';

where 2 was/is the original admin account

yourID is your account ID ... the one you say is now manager?

otherID is a co-worker that has been a site admin ... their account ID number.

Could do just yourID number if others not involved.

'SoS', Ken

Average of ratings: Useful (3)
In reply to Ken Task

Re: Creating an admin user from phpmyadmin

by Ismail Fayed -
Hello Ken,

Thanks for your response and suggestion. I have tried this approach in the config.php but generated database error. Is there another way for this from phpmyadmin?

Thanks again
Ismail
In reply to Ismail Fayed

Re: Creating an admin user from phpmyadmin

by Ken Task -
Picture of Particularly helpful Moodlers

"I have tried this approach in the config.php but generated database error"

What was the error?  And show me the line you added to config.php.

One other way ... again not in phpmyadmin ... but via ssh.

cd /path/to/moodlecode/admin/cli/

Issue:

[root@server cli]# php reset_password.php
== Password reset ==
Enter username (manual authentication only)

Admin account ... your account should have been a manual account.

By entering a username at the prompt above, if found, you will get a prompt for the password.   It has to follow the password policy for the site.

Dunno that?   Ok, then at same location, use the cfg.php script like so:

php cfg.php |grep password

you should see the following among a couple of others:

minpasswordlength    8
minpassworddigits    1
minpasswordlower    1
minpasswordupper    1
minpasswordnonalphanum    1

Password you set in clear text where you can see it as you type:

Your site may/may not have same requirements, but if it does above means:

8 characters long ... must have one digit ... one lowercase letter .. one upper case letter and one non alpha neumeric character like '!'.

Changing via PHPMyAdmin ... what you see in the password column is md5 hashed with an unkown hash.    Good luck there!

'SoS', Ken



In reply to Ken Task

Re: Creating an admin user from phpmyadmin

by Felipe Guterres -
Thank You Ken!

It worked for me, I export the user from another base, and import the base, I changed the password with CLI. And finally I changed the config.php

Hugs,
Felipe
In reply to Ismail Fayed

Re: Creating an admin user from phpmyadmin

by Randy Thornton -
Picture of Documentation writers
And for the record, the way to do this directly in the database via phpmyadmin or other tool is to add the user id number to the mdl_config table where the 'name' equals "siteadmins". (This may be row 23 in the table, since it is built during install.)

The 'value' is a comma delimited list of the id numbers of admin users. The default value is 2, for the main predefined admin. Add any other admins here, comma separated. For example, if you want to add user 3 as an admin, edit the value and put 2,3 as the value. You may need to flush caches for this to take effect right away, since lots of user info is cached.

This amounts to doing the same thing as adding a user to the siteadmin list in Site admin > Users > Permissions > Site administrators, but note that this will not be logged in the Moodle log table if you do it directly in the database, for obvious reasons.
Average of ratings: Useful (1)