PHP dotenv loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically.
You should never store sensitive credentials in your code. Anything that is likely to change between deployment environments – such as database credentials or credentials for 3rd party services – should be extracted from the code into environment variables.
Add your application configuration to a .env file in the root of your project. Make sure the .env file is added to your .gitignore so it is not being checked-in.
DEFINE
S3_BUCKET="dotenv" SECRET_KEY="souper_seekret_key"
LOAD
$dotenv = new Dotenv\Dotenv(__DIR__); $dotenv->load(); // OR WITH filename $dotenv = new Dotenv\Dotenv(__DIR__, 'myconfig'); $dotenv->load();
ACCESS
$s3_bucket = getenv('S3_BUCKET');
$s3_bucket = $_ENV['S3_BUCKET'];
$s3_bucket = $_SERVER['S3_BUCKET'];
