Search code examples
phpconfigurationreleasedevelopment-environmentproduction-environment

What methods are used for differentiating between production/staging/development environments in PHP applications?


Obviously this is a common issue: we have PHP web applications that are managed by git or other SCMs, and are deployed (ideally) in 3+ different environments that should be extremely similar. The only differences should be in the specific configuration such as addressing of external resources (eg: database host, memcache, etc).

Here are the three methods I've seen or used:

  1. Maintain an array of hostnames => environment types: $hosts = array ('host1.example.com' => 'production', 'staging.example.com' => 'staging' ...)
  2. Have a config file that is in the .gitignore (or equivalent for other SCMs) with an example version to copy and edit
  3. Use http.conf to set an env_var: "SetEnv ENVIRONMENT dev" in your http.conf and then $environment = get_env('ENVIRONMENT'); in your scripts.

Are there other methods as well? I know each of these have benefits and pitfalls--what are those?


Solution

  • We use Jenkins to pull from git server whenever a push event is issued.

    In it's config we have a line that is different for each server:

    mv config_<env>.php config.php
    

    while config.php is in git ignore.