Skip to content

Instantly share code, notes, and snippets.

@MwirabuaTimothy
Last active August 29, 2015 14:27
Show Gist options
  • Save MwirabuaTimothy/099ec8eba3b119e8ceae to your computer and use it in GitHub Desktop.
Save MwirabuaTimothy/099ec8eba3b119e8ceae to your computer and use it in GitHub Desktop.
Managing environment configurations on laravel 4 and keeping private keys from source control

On your local source code:

define environments in bootstrap/start.php

$env = $app->detectEnvironment(function(){
	return gethostname() == 'blackpearl' ? 'production' : 'local';
}); 

create app/config/production folder

create .gitignore file in it, content:

# Ignore everything in this directory
*
# Except this file
!.gitignore

create app/config/local folder

create .gitignore file in it, content:

# Ignore everything in this directory
*
# Except this file
!.gitignore

copy the following app/config/ files into app/config/local:

app.php
mail.php
database.php

clear keys in default config files - app/config/*.php

files - app, database, mail

for packages ( app/config/package/..):

define all your private keys on local/app.php

	e.g. 'xyz' =>'very-private-key'

refer to them in package/config/.. files using the Config class

	e.g. Config::get('app.xyz')

On the server:

cd project-name/app/config

cp app.php production 
nano production/app.php
	set debug, url, timezone, key, package-keys (copy all from local code - app/config/local)

cp database.php production 
nano production/database.php
	set database, username, password
	
cp mail.php production 
nano production/mail.php
	set from->address, from->name, username, password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment