Is there a best practice for including your wp-config.php
file in your version control repository?
I’m considering creating a new site with this type of configuration, (similar to Alex King and Mark Jaquith):
/index.php
/local-config.php
/wp-config.php
/wp/ (core)
/wp-content/ (plugins, themes, etc.)
How can I do this without exposing my passwords to git, in case this repository ever becomes public?
Especially in Mark’s post, it looks like the local-config.php can store local database details and passwords, but the production ones stay in the wp-config.php. Is this too much trouble and should I just leave wp-config.php unversioned?
Here is how I do it and I haven’t come across anything better than this. I keep a different version of wp-config.php file under version control and then keep a file one directory above which holds all the database credentials and salts/keys. Also this way, I am able to distinguish between the type of setup I am running and do things differently on basis of that.
Here is the
wp-config.php
I keep undergit
(https://gist.github.com/1923821):And here is the local config file which I keep one directory above WordPress root and this also makes it outside the web accessible directory, so in case apache stops parsing PHP files and start throwing them out, our database credentials are still safe (https://gist.github.com/1923848):
This way if the above file is named
local-config.php
, my system behaves like a local install. If its namedstaging-config.php
, it behaves like a staging install and if its namedproduction-config.php
. It helps me have different values of certain constants like debugging have different values under different environments and still have everything under SCM (git). Possiblities are endless and there is no hackery required for different enviornments.This makes sure you never reveal any sensitive information to public anyway and I use this just to start off any project I work on, I have stronger keys in place by default and as soon as I add them to the second config file one directory above, those are used instead of the ones defined here. Bliss!
If your
wp-config.php
file is in version control, then any passwords it contains will also be in version control. The only way to avoid that is to not put the file in version control.My gut feeling would be to keep
wp-config.php
unversioned entirely. But there are some ways around it.Extract the part of
wp-config.php
that contains your passwords and hashes into a separate file andinclude()
it in the regularwp-config.php
file. Then, placewp-config.php
under version control, but keep yourinclude()
file separate.wp-config.php
:You can see now that passwords and hashes are not included in
wp-config.php
at all.conf.php
:But honestly, at this point you’re just adding a redundant level of abstraction here. The entire reason
wp-config.php
is separate in the first place is because it’s environment-specific. You shouldn’t be copying it from a local server to production at all … so it shouldn’t be under version control at all.Mark’s example assumes you are working with a private repo:
Instead of defining the credentials you could just as easily create a production-config.php file and include it within the conditional check:
Then in your unversioned production-config.php:
You could commit the
wp-config.php
file to the repository without your secret strings, then run:This will tell git to assume that the file is, well, unchanged.