symfony: development, integration and production environments

Translation of the original in Catalan. Read it in: CatalàCastellano

When developing a software project I like to work in 3 environments. While the project is being developed it is good to have a space of variables (or namespace) in the application that corresponds to the settings of the development server (usually a machine of your own), for example the paths, urls, database data, etc. all of this has to be as separated as possible from the code so that the configurations for the integration and production environments can be created.

The integration environment is a machine in the client's development environment, with characteristics as similar as possible to the production environment. That is, the configuration data of the namespace has to point to services, if possible of the same version as the production environment. That way we can test the application and improvements to the application before moving it to production. Finally we have to have the namespace for production with the working data.

In order to support all this symfony supports, in a great many configuration files, the possibility of defining the environment, in the case I am describing, 'dev', 'int' and 'prod'. In the front controller of each application we can define this namespace and then the right part of the configuration files will be accessed.

For example, if we look at the file config/databases.yml where symfony defines the database systems that our application uses in each of the environments we could have something like this:

dev:
  nombbdd:
    class:           sfPropelDatabase
    param:
      phptype:       mysql
      hostspec:      localhost
      database:      nombbdd
      username:      userbbdd
      password:      passbbdd
int:
  nombbdd:
    class:          sfPropelDatabase
    param:
      phptype:      oracle
      username:     nombbdd
      password:     nombbdd
      hostspec:     hostint
      database:     NULL
prod:
  nombbdd:
    class:          sfPropelDatabase
    param:
      phptype:      oracle
      username:     nombbdd
      password:     nombbdd
      hostspec:     hostprod
      database:     NULL

It is when the front controller is called that symfony says which environment we will be working in; for example, for an application called myapp we could have these three front controllers, one for each environment:

Development environment web/myapp_dev.php:

<?php
define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));
define('SF_APP',         'myapp');
define('SF_ENVIRONMENT', 'dev');
define('SF_DEBUG',       true);
#
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
#
sfContext::getInstance()->getController()->dispatch();
?>

Integration environment web/myapp_int.php:

<?php
define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));
define('SF_APP',         'myapp');
define('SF_ENVIRONMENT', 'int');
define('SF_DEBUG',       true);
#
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
#
sfContext::getInstance()->getController()->dispatch();
?>

Production environment web/myapp.php:

<?php
define('SF_ROOT_DIR',    realpath(dirname(__FILE__).'/..'));
define('SF_APP',         'myapp');
define('SF_ENVIRONMENT', 'prod');
define('SF_DEBUG',       false);
#
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
#
sfContext::getInstance()->getController()->dispatch();
?>

As you can see, both development and integration will show us debug information and production will hide the error messages and always report the error "internal server error". Moreover we can see that all three environments call the same global configuration file config/config.php.

If you want more information about this topic I recommend the following links from the symfony documentation: