Use environment variables in Magento 1 local.xml, uses getenv to get the values

1.0.3 2018-03-26 12:24 UTC


Original module: which used $_SERVER vars which did not work for us using HHVM.

In our development workflow, our webservers provide environment configuration information to our applications via environment variables (i.e. MAGE_DB_HOST, MAGE_DB_USER etc). This doesn't sit well with Magento's XML based configuration approach.

This little hack allows us to use '$MAGE_DB_HOST' and any other environment variables in our XML configuration files.

You can also specify a default value in case the envvar is missing or empty by appending it with double pipe symbols (e.g. '$MAGE_DB_HOST||localhost').


Example part of our local.xml...

                    <initStatements><![CDATA[SET NAMES utf8]]></initStatements>