1

I'm developing from my Windows laptop but need to test my development on my shared Linux hosting. I have thrown together the following in place of the normal $application_path = "application"; line.

$env['laptop']['ip'] = '127.0.0.1';
$env['laptop']['host'] = 'MATT-WINDOWS7';
$env['laptop']['path'] = 'private';

$env['mattpotts']['ip'] = '12.34.56.78'; $env['mattpotts']['host'] = 'my.webhost.com'; $env['mattpotts']['path'] = '../private/blah';

 $ip = $_SERVER['SERVER_ADDR'];
 $host = php_uname('n');
 foreach($env as $e)
  if($e['ip'] == $ip && $e['host'] == $host)
   $application_folder = $e['path'];
 unset($env);
 if(!isset($application_folder))
  die('application folder not set');

...which works fine for setting the application path but now I'm running into trouble with the need for a database config for each environment.

I can make it work with a few simple ifs but I was wondering if there's a best practice solution to this one.

Cheers

5 Answers 5

6

Use revision control such as Subversion. Have one configuration file deployed to your test environment and a modified version checked out in your development environment. Simply tell your client to not commit those configuration changes so they don't make it to your testing/production environment.

This is definitely the best practice solution :)

P.S. If you don't feel like setting up a Subversion server, there's always hosted solutions like Beanstalk and if you're on Windows, TortoiseSVN is a slick client.

2

If you don't feel like setting up subversion you can always detect what site you're on by looking at SERVER_NAME. In a CI site in the past I used the following within my config.php to figure out dev vs production servers:

if ($_SERVER['SERVER_NAME'] == 'www.mysite.com') {
    $config['log_path'] = '/var/log/site/';
} else {
    $config['log_path'] = '/var/log/dev_site/';
}

You can use this anywhere you need to have different variables based on environment. That being said hard-coding stuff like this into your code isn't always the best idea.

1
  • Isn't it unsafe to check by domain? At least laravel frameworks says so: laravel.com/docs/4.2/upgrade "For security reasons, URL domains may no longer be used to detect your application environment." Only weird thing is that I only find this in laravel docs, not somewhere else on the internet so far
    – Dariux
    Jan 13, 2015 at 8:00
1

Here's a nice clean solution to running multiple production environments on a single codebase:

http://philsturgeon.co.uk/news/2009/01/How-to-Support-multiple-production-environments-in-CodeIgniter

1
  • After switching from using Zend Framework, where setting the environment is a lot more central to the app, I really need something simple but effective like this. Cheers.
    – wheresrhys
    Dec 6, 2010 at 21:36
1

As Phil's solution is no longer accessible, here's another solution that'll provide you with the exact same solution.

Here's the link to the Git repo: https://github.com/jedkirby/ci-multi-environments and this is a brief explanation of the module: http://jedkirby.com/blog/2012/11/codeigniter-multiple-development-environments

0

Phil Sturgeons page has moved to here: http://philsturgeon.co.uk/blog/2009/01/How-to-Support-multiple-production-environments-in-CodeIgniter

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.