Environments

The support of environments helps FuelPHP and your app to make decisions based on the environment setting. FuelPHP itself uses the environment setting to load/overwrite additional config setting based on which environment is currently active.

Environments list

FuelPHP has four predefined environments.

Set Your Environment

Setting your environment is done by setting the FUEL_ENV server var or manually changing the setting in fuel/app/bootstrap.php.

// Inside app/bootstrap.php

/**
 * Your environment.  Can be set to any of the following:
 *
 * Fuel::DEVELOPMENT
 * Fuel::TEST
 * Fuel::STAGE
 * Fuel::PRODUCTION
 */
Fuel::$env = (isset($_SERVER['FUEL_ENV']) ? $_SERVER['FUEL_ENV'] : Fuel::DEVELOPMENT);

Environments and Config

Based on the environment the app is set to, the Config class looks for environment-specific config files. The config class will look for the same config file name in a directory that's named after the current environment. Here is an example to illustrate this:

app/
  config/
    stuff.php
      development/
        stuff.php
      production/
        stuff.php

When your environment is set to \Fuel::DEVELOPMENT, the settings from stuff.php are merged with development/stuff.php. If the environment setting is set to any other than \Fuel::DEVELOPMENT, the extra config file is not loaded. The same goes for any other environment setting you might use.

A real-life example for this is the database configuration. There are no default configuration settings (this is possibly very dangerous). There are only environment-specific config settings.

Using Apache configuration

You can use the Apache configuration statement SetEnv to set the environment your application should run in. In most cases this is easier then using an environment variable, and in some cases the only option if you don't have commandline access to your server.

// run this application in production mode
SetEnv FUEL_ENV production

The variable name FUEL_ENV should be specified in UPPERCASE, the environment name in lowercase.

Setting the environment for oil

When using a *unix operating system, you can use the env command to define the variable before starting oil.

$ env FUEL_ENV=production php oil -v

At the moment we don't know how this can be done in Windows without the use of a batch file that adds the environment variable. If you know how, let us know, or send us a pull request adding it to this page!