CodeIgniter Forums
Multiple Environment Setup Help - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Multiple Environment Setup Help (/showthread.php?tid=53964)

Multiple Environment Setup Help - El Forum - 08-16-2012

So I know there is the config class and have read the documentation...
I develop on my local and when I go to put it on my server I find myself having to change setting in several different files:


Anyway to setup these files so I don't have to change them when I go back and forth?

Multiple Environment Setup Help - El Forum - 08-16-2012

Well, there is an obvious way for all PHP files:

if ($_SERVER['SERVER_NAME'] === '') {
$config['param'] = 'value';
} elseif ($_SERVER['SERVER_NAME'] === 'local.development') {
$config['param'] = 'value';

There is also a way to "override" config items, which may be cleaner. Add something like this to index.php:

$assign_to_config['name_of_config_item'] = 'value of config item';

You can obviously keep these in a separate file and do something like:

if ($_SERVER['SERVER_NAME'] === '') {

and keep the $assign_to_config array in that override.

As far as .htaccess goes, it has a condition like:
RewriteCond %{SERVER_NAME} =

But I'm personally a lighttpd man, so I don't know all the details Smile

Multiple Environment Setup Help - El Forum - 08-16-2012


Plenty of info there for setting up environments and their config values. Then, as dejan said, you just need to add some logic somewhere that figures out what environment it's in.