Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Changing Database and Environment settings
  • Hi guys, A quick question about changing the DB and Environment settings on Fuel. We are building a web app and have it on our local, development and live servers. Each server is using a different DB. What is the best way you can change that automatically depending on which server it is on? Currently, I have changed the config.php file to instead of returning array straight off; it puts it in a variable, does a check for the URL and changes the Env respectively. Then returns the array. Is there something I've missed to do this better, seems the only way I can do it at the moment. Cheers for getting back to me. I've copied the code at the bottom of this post. Thanks,
    Steve
    <?php
    /**
     * Fuel is a fast, lightweight, community driven PHP5 framework.
     *
     * @package    Fuel
     * @version    1.0
     * @author     Fuel Development Team
     * @license    MIT License
     * @copyright  2010 - 2011 Fuel Development Team
     * @link       [url=http://fuelphp.com]http://fuelphp.com[/url]
     */
    
    $config = array(
    
     /**
      * base_url - The base URL of the application.
      * MUST contain a trailing slash (/)
      *
      * You can set this to a full or relative URL:
      *
      *     'base_url' => '/foo',
      *     'base_url' => 'http://foo.com/'
      *
      * Set this to null to have it automatically detected.
      */
     'base_url'  => null,
    
     /**
      * index_file - The name of the main bootstrap file.
      *
      * Set this to false or remove if you using mod_rewrite.
      */
     'index_file' => false,
    
     /**
      * Your environment.  Can be set to any of the following:
      *
      * Fuel::DEVELOPMENT
      * Fuel::TEST
      * Fuel::STAGE
      * Fuel::PRODUCTION
      */
     'environment' => Fuel::DEVELOPMENT,
    
     /* ... Rest of the array removed for brevity... */
    
    );
    
    // Switch Env depending on the HTTP Host.
    
    switch(strtolower($_SERVER['HTTP_HOST'])) {
     case 'local.dev':
     case 'www.local.dev':
      $config['environment'] = Fuel::DEVELOPMENT;
     break;
     
     case 'test.dev':
     case 'www.test.dev':
      $config['environment'] = Fuel::TEST;
     break;
     
     case 'stage.dev':
     case 'www.stage.dev':
      $config['environment'] =  Fuel::STAGE;
     break;
     
     case 'production.dev':
     case 'www.production.dev':
      $config['environment'] =  Fuel::PRODUCTION;
     break;
     
     default:
      $config['environment'] = Fuel::DEVELOPMENT;
     break;
    }
    
    return $config
    /* End of file config.php */
    
    
  • Use SetEnv in your .htaccess file. And don't replace it on the server :)
  • Frank Bardon wrote on Monday 25th of July 2011:
    Use SetEnv in your .htaccess file. And don't replace it on the server :)

    And if you don't know how to do that:
    SetEnv FUEL_ENV development
    

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion