Skip to content

Instantly share code, notes, and snippets.

@stevenwoodson
Last active August 29, 2015 13:56
Show Gist options
  • Save stevenwoodson/8935510 to your computer and use it in GitHub Desktop.
Save stevenwoodson/8935510 to your computer and use it in GitHub Desktop.
Laravel 4 Detect environment set to use the servers SERVER_NAME, default to local for artisan commands
$env = $app->detectEnvironment(function(){
// For artisan commands, default to localhost
$serverName = 'localhost';
if ( isset($_SERVER["SERVER_NAME"]) && strlen($_SERVER["SERVER_NAME"]) > 0 ){
$serverName = $_SERVER["SERVER_NAME"];
}
// List of environments with the server name as the key
$serverNames = array(
'staging.net' => 'staging',
'productionserver.com' => 'production'
);
if ( isset($serverNames[ $serverName ]) ){
return $serverNames[ $serverName ];
} else {
return 'production';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment