17

What is the difference between app/etc/config.xml and app/etc/local.xml?

I feel like some configurations are duplicated. I always have to deal w/ local.xml, so what is the purpose of having all that other stuff in config.xml and when is it used?

1 Answer 1

15

config.xml and local.xml are loaded together, along with any other xml file you place in app/local. They are loaded in Mage_Core_Model_Config::loadBase()

public function loadBase()
    {
        $etcDir = $this->getOptions()->getEtcDir();
        $files = glob($etcDir.DS.'*.xml');
        $this->loadFile(current($files));
        while ($file = next($files)) {
            $merge = clone $this->_prototype;
            $merge->loadFile($file);
            $this->extend($merge);
        }
        if (in_array($etcDir.DS.'local.xml', $files)) {
            $this->_isLocalConfigLoaded = true;
        }
        return $this;
    } 

Magento will work if you move the contents of config.xml to local.xml and remove entirely config.xml.
This separation exists for a reason.
config.xml contains (let's call them) settings that do not depend on the environment where Magento is installed.
local.xml contains environment dependent settings: DB connection, cache engine, encryption key, session handler.
This way a part of the settings can be versioned (config.xml) and you only have a small file depending on the environment.

2
  • 4
    Also during upgrade config.xml will be overwritten and local.xml will not be. And finally local.xml is actually loaded twice, at start and end of config parsing. Since it is all merged in one config object, anything you put in local.xml will override any other config in any module. May 21, 2013 at 21:20
  • 4
    @PetarDzhambazov "at end of config parsing" is not entirely correct/clear, as the values from core_config_data are parsed and merged in after local.xml.
    – benmarks
    May 21, 2013 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.