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?

1 Answer 1


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 :-)

  • 1
    Yeah, I don't include local.xml in the repo, either (.gitignore).
    – laketuna
    Commented Mar 13, 2014 at 19:14
  • Good point in regards to the .gitignore
    – Zabs
    Commented Mar 14, 2014 at 10:02
  • @Fabian we are looking at deployment techniques funnily enough now as well, We are using Git for version control but haven't decided which deployment facility to use yet. I presume your method means the local.xml is only created at the deployment stage & no sooner so it never appears in git repo?
    – Zabs
    Commented Mar 14, 2014 at 10:32
  • Zabs: Correct. You have to save the database data somewhere, but you can get them from there, create a local.xml and write them to the server. And you should have a look on capistrano and magentify: github.com/alistairstead/Magentify Commented Mar 14, 2014 at 12:02
  • Wow.. you read our minds we decided on capistrano :)
    – Zabs
    Commented Mar 14, 2014 at 17:28

Your Answer

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

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