I've started looking at Heroku for application hosting and deployment and it appears that my configuration constants need to be stored in environment variables. I can do this in Heroku, but my application might also be deployed to shared servers and it may not be secure according to this question.
Basically I want the information to be read from a configuration file if it is present, otherwise try to read from the environment variables (in the case of Heroku).
- Is this the best way of doing it?
- Are there security implications?
settings.php
<?php
define('DB_URL', 'mysql://root:password@localhost:3306/database');
define('APP_URL', '[::1]');
define('APP_URL_PATH', '/path/to/application');
define('FOO', 'more things');
config.php
<?php
if (!is_file('settings.php')) {
require 'settings.php';
return;
}
define('DB_URL', getenv('DB_URL'));
define('APP_URL', getenv('APP_URL'));
define('APP_URL_PATH', getenv('APP_URL_PATH'));
define('FOO', getenv('FOO'));
index.php (and other application files)
<?php
require 'config.php';
$app = new \Slim\Slim\App();
// code
$app->run();