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:
- Maintain an array of hostnames => environment types:
$hosts = array ('host1.example.com' => 'production', 'staging.example.com' => 'staging' ...) - Have a config file that is in the .gitignore (or equivalent for other SCMs) with an example version to copy and edit
- Use
http.confto 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?
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:
while config.php is in git ignore.