Magento – Using custom Environment Variables for sensitive database info

local.xmlmagento-1.8

I know Magento stores the database connection details within the 'local.xml' file, however our firm is trying to avoid passwords and other sensitive data being stored within our git repo's for security purposes.

I know you can create Environment Variables easily via an .htaccess file, but I'm hoping to find a workable solution that will enable me to set this database information dynamically from a environment variable.

As the local.xml is an XML file and as this is a non dynamic/server-side filetype we cannot use it to read environment variables.

Would there be a way to somehow add in some hook/custom behaviour to Magento in which I could replace the local.xml with a PHP file that will allow me to pull in these environment variables?

So in a sense, the local.XML would become a local.PHP file with the ability to read my own custom environment variables such 'DB_HOST', 'DB_USERNAME', 'DB_PASSWORD' rather than having them already set in the xml file as 'localhost', 'root', 'password123' etc..

Any ideas on how best to achieve this, or are there any existing Magento add-ons/extensions/mods that will allow me to do this?

Best Answer

Do you have a deployment? Just create the local.xml with your deployment, where ever the data in it comes from.

Btw, local.xml shouldn't be stored in git, with or without db data :-)