Info
Content

Site Configuration


There's a handy CLI tool available in recent versions of Moodle to get and set site and plugin/component configuration:

php admin/cli/cfg.php --help
Displays the current value of the given site setting. Allows to set it to the given value, too.

Usage:
    # php cfg.php [--component=<componentname>] [--json] [--shell-arg]
    # php cfg.php --name=<configname> [--component=<componentname>] [--shell-arg] [--no-eol]
    # php cfg.php --name=<configname> [--component=<componentname>] --set=<value>
    # php cfg.php --name=<configname> [--component=<componentname>] --unset
    # php cfg.php [--help|-h]

Options:
    -h --help                   Print this help.
    --component=<frankenstyle>  Name of the component the variable is part of. Defaults to core.
    --name=<configname>         Name of the configuration variable to get/set. If missing, print all
                                configuration variables of the given component.
    --set=<value>               Set the given variable to this value.
    --unset                     Unset the given variable.
    --shell-arg                 Escape output values so that they can be directly used as shell script arguments.
    --json                      Encode output list of values using JSON notation.
    --no-eol                    Do not include the trailing new line character when printing the value.

Here are a few good examples of how to use it.

For a site configuration value e.g. the list of user ids who are site administrators.

php admin/cli/cfg.php --name=siteadmins
2

To search for a configuration value that you think might be set use good old grep:

php admin/cli/cfg.php | grep wwwroot
wwwroot	https://{yoursite.com}

For any component/plugin use the {type}_{name} format i.e. frankenstyle like tool_log or enrol_manual:

php admin/cli/cfg.php --component=tool_log
enabled_stores	logstore_standard
exportlog	1
version	2018120300

php admin/cli/cfg.php --component=enrol_manual
defaultenrol	1
enrolperiod	0
enrolstart	4
expiredaction	1
expirynotify	0
expirynotifyhour	6
expirythreshold	86400
roleid	5
status	0
version	2018120300

You can also output json if you like (though you need to format json accordingly).

php admin/cli/cfg.php --component=enrol_meta --json | python -m json.tool
{
    "coursesort": "sortorder",
    "nosyncroleids": "",
    "syncall": "1",
    "unenrolaction": "3",
    "version": "2018120300"
}

The set and unset options are particularly handy if you the site is not working due to a configuration option For example lets just set the auth methods available to email and remove saml2 and a2fa.

php admin/cli/cfg.php --name=auth
email,saml2,a2fa

php admin/cli/cfg.php --name=auth --set=email
php admin/cli/cfg.php --name=auth
email
No Comments
Back to top