Skip to content

Use environment variables in your Magento local.xml configuration file

Notifications You must be signed in to change notification settings

huynhphan89/magento-config-envvars

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Ability to use envvars in Magento config

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').

Usage

Example part of our local.xml...

...
            <default_setup>
                <connection>
                    <host>$MAGE_DB_HOST</host>
                    <username>$MAGE_DB_USER</username>
                    <password>$MAGE_DB_PASS</password>
                    <dbname>$MAGE_DB_NAME</dbname>
                    <initStatements><![CDATA[SET NAMES utf8]]></initStatements>
                    <model><![CDATA[mysql4]]></model>
                    <type><![CDATA[pdo_mysql]]></type>
                    <pdoType></pdoType>
                    <active>1</active>
                </connection>

...

About

Use environment variables in your Magento local.xml configuration file

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%