It’s possible to move wp-config.php up one directory level for security, i.e. into the directory above public_html (sometimes called home or a user name, depending on the web host).
“You can move the wp-config.php file to the directory above your WordPress install”, according to http://codex.wordpress.org/Hardening_WordPress#Securing_wp-config.php And I have done that with one WP sites’ wp-config.php file.
But how does one do that with multiple WP sites in their own folders in public_html? Is there a way to rename multiple wp-config.php files – something like wp-config1.php and wp-config2.php, etc. – in the home directory for each different WP site? And use .htaccess or some other method to enable each WP install to find its own wp-config.php file?
One solution I guess is Multisite, but that’s not possible in this case.
Use one main
wp-config.php
and name the others according to the name of the host:In your main
wp-config.php
write:Sterling’s method above was very attractive because the code was so simple but it didn’t work for me. Fuxia’s method assumed different domain names which wasn’t in my case. My case is multiple WP installs/instances under one domain name. So I combined both their methods and came up with the following which worked for me:
Copy all the wp-config.php files to outside your web root folder (the directory above public_html), then rename them to something like mysite-wp-config.php and then inside the actual installs, you can have a file called wp-config.php then do this inside that file:
Hope that helps somebody.
There are two ways to do this. From your question, it sounds like you have this structure currently:
And what you want to do is also move the
wp-config.php
file for your other sites out of the site root as well. You’re correct in pointing out that this will lead to some conflicts because every site will try to includewp-config.php
but can’t all use the same one.The bigger problem is that there is no way to use
wp-config.site1.php
orwp-config1.php
or any other variation to keep things separate without hacking core.If you take a look at the code in
wp-load.php
you’ll see this:WordPress will only look one directory past its current location and will only look for
wp-config.php
.Your best bet would be to push everything up one level further to give yourself some separation. Then point your Apache vhosts file at the new folder locations. So set your directory structure up like this:
Your vhosts file will then point
www.site1.com
to/home/public_html/site1/wordpress
instead of/home/public_html/site
. Yes, it’s a bit more convoluted, but the only way you can avoid this issue.You could do this:
Copy all the wp-config.php files into the level above the installs, then rename them to something like mysite-wp-config.php and then inside the actual installs, you can have a file called wp-config.php then do this inside that file:
This is a theory, I have not tested it.