I currently have a number of different settings.php files because I'm developing on localhost, test on two temporary servers and deploy to yet another which doesn't point to the final domain yet. So, I have a whole bunch of settings.php files which basically all do the same thing. Is it possible to define all things they have in common in a single settings file rather than to duplicate all this information?

Thanks,
Luke

Comments

gpk’s picture

If the only difference between the files is e.g. the $db_url then you could remove this line from settings.php, insert it into settings.dburl.php, and back in settings.php insert require './settings.dburl.php;' - that would then be the only thing you needed to change :-)

gpk
----
www.alexoria.co.uk

pan69’s picture

Thanks for your response but I'm not entirely sure what you're saying. What settings.php are you exactly referring to that has the include?

My structure is like this:

/sites
/domain1.com
settings.php
/domain2.com
settings.php
/default
settings.php

Most of what is in settings.php it the same. What I would like is this:

/sites
/domain1.com
settings.php <- includes ./shared_settings.php
/domain2.com
settings.php <- includes ./shared_settings.php
/default
settings.php <- includes ./shared_settings.php
shared_settings.php

In this case all the settings that are the same are kept in shared_settings.php and the domain specific version includes this file and sets only its specific variables. However, it this way the include (and all it's variations) throw up an recursive error.

Any ideas welcome!

gpk’s picture

Well there are bascially 2 "ways" of doing this and I happened to suggest the other way (that each folder keeps the common stuff in the main settings.php - which is the same across all domains - and at the appropriate place, or just at the bottom, includes the domain-specific settings).

Your way could be better as you could put the shared file at /sites/shared/shared_settings.php.
Then in each domain's settings.php you could just include ../shared/shared_settings.php at the very top, and define your domain-specific variables ($db_url and the like) at the bottom.

This looks much like what you are doing.

>the include (and all it's variations) throw up an recursive error
You'd need to be more specific.. but make sure shared_settings.php doesn't have an include statement..

gpk
----
www.alexoria.co.uk

pan69’s picture

Hi. Thanks again for answering. I figured out what the problem was. Apparently the scope of settings.php is in the / of the site. So instead of saying include("../shared/settings.php") I need to do include("sites/shared/settings.php").

Cheers!

gpk’s picture

Doh, the running script is index.php of course ... !

gpk
----
www.alexoria.co.uk