Recent Posts


N98-Magerun: Config Commands


Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

This article is part of a longer series covering the n98-magerun power tool

Magento is a module based system — each code module has a file named config.xml which contains configuration information related to the module. Magento will merge all the config.xml files into a single global configuration tree. This tree is then available for all modules and core library code to read from. This configuration tree is also where the admin console’s system configuration variables are stored.

Today we’ll review the three n98-magerun command related to the global configuration tree.

$ n98-magerun.phar list config


Available commands for the "config" namespace:
  config:dump   Dump merged xml config
  config:get    Get a core config item
  config:set    Set a core config item

The config:dump command will dump the entire merged tree to your console.

$ n98-magerun.phar config:dump
<?xml version="1.0"?>

        Sun, 01 Jul 2012 17:06:09 +0000

If that much XML is a little overwhelming, you can use an xpath expression to filter the results.

$ n98-magerun.phar config:dump global/models/catalog
<?xml version="1.0"?>



The other two items related to the system configuration variables. If you have a variable’s path, you can grab its currently set value

$ n98-magerun.phar config:get web/seo/use_rewrites
| Path                 | Scope    | Scope-ID |   |
| web/seo/use_rewrites | default  |    0     | 1 |

You can also specify a partial path to see all set configuration values — just make sure your path ends with a trailing /

$ n98-magerun.phar config:get web/
| Path                  | Scope    | Scope-ID | Value                       |
| web/secure/base_url   | default  |    0     | |
| web/seo/use_rewrites  | default  |    0     | 1                           |
| web/unsecure/base_url | default  |    0     | |

The config:get command will only fetch a value if its been set. If there’s no entry in core_config_data, this command will not return the value set in a config.xml file’s “ node.

Since we have a command to get configuration variables, it’s no surprise there’s a command to set configuration variables as well.

$ n98-magerun.phar config:set web/seo/use_rewrites 0
web/seo/use_rewrites => 0

$ n98-magerun.phar config:get web/seo/use_rewrites
| Path                 | Scope    | Scope-ID |   |
| web/seo/use_rewrites | default  |    0     | 0 |

Without any options, the command will set the value for the default scope, and with a scope ID of 0. Valid values for Scope are default, websites, or stores. The Scope-ID field is a numeric ID that correlates to the the website or store ID the configuration value should apply to.

We can find the syntax for these options by looking at the config:set command’s help

$ n98-magerun.phar help config:set
 config:set [--scope[="..."]] [--scope-id[="..."]] [--encrypt] path value

 path                  The config path
 value                 The config value

 --scope               The config value's scope (default: "default")
 --scope-id            The config value's scope ID (default: "0")

Looking at the Usage section above, we see n98-magerun uses the -- option style, followed by an equal sign. That means if we wanted to set values scoped for the store with an ID of 1, we’d use the following

$ n98-magerun.phar config:set --scope=stores --scope-id=1 web/seo/use_rewrites 0
web/seo/use_rewrites => 0

It’s important to be careful here — Magento UI for setting scoped configuration variables including options for hiding certain configuration fields at certain scope levels. The n98-magerun tool will allow you to bypass these restrictions by setting values directly

For example, Magento disables setting template path hints at the default level — both to avoid hints in the admin console, as well as ensure a developer doesn’t accidentally turn on hints for a store they’re not working on. You can bypass this restriction with

$ n98-magerun.phar config:set dev/debug/template_hints 1
dev/debug/template_hints => 1

There’s certainly a debate to be had about using user interface to enforce data restrictions — but that’s a larger conversation for another time. For now, just remember that n98-magerun is a power tool: understand what it’s doing before embracing it.

Copyright © Alan Storm 1975 – 2022 All Rights Reserved

Originally Posted: 18th April 2013