I'm hosting my PHP project on AWS EC2 servers, using Elastic Beanstalk. I've set up my ENV Vars using php dotenv
, which seem to be getting my vars just fine from my root .env
file:
DbConnect.php:
require '../vendor/autoload.php';
$dotenv = new Dotenv($_SERVER['DOCUMENT_ROOT']);
$dotenv->load();
$DB_HOST = getenv('DB_HOST');
$DB_USERNAME = getenv('DB_USERNAME');
$DB_PASSWORD = getenv('DB_PASSWORD');
$DB_DATABASE = getenv('DB_DATABASE');
$mysqli = new mysqli($DB_HOST, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE);
So, in AWS Management Console, I set up the same named ENV vars within software configuration, git pushed, and re eb-deployed. I'm getting a 500 error because the EC2 ENV vars don't seem to be picking up.
Is there something else I need to do?
Update:
eb printenv
displayed the correct env var values.
eb printenv
to make sure the env vars are what you expect them to be. – Nick Humrich$_SERVER['DB_HOST']
syntax for all the envvars instead of getenv? – Nick Humricheb printenv
printed the correct values – Growler$_ENV['DB_HOST']
as well. Though, they should all work the same. You could also validate the envvars are correctly making it to the php container by looking atphpinfo
result. – Nick Humrich