Skip to content

Instantly share code, notes, and snippets.

@u007
Created July 13, 2023 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u007/b76f1e121d2dcf612b9e86bd190f100d to your computer and use it in GitHub Desktop.
Save u007/b76f1e121d2dcf612b9e86bd190f100d to your computer and use it in GitHub Desktop.
php code to generate .env from elasticbeanstalk environment variables
<?php
// setup .env from $_ENV
file_put_contents('/var/www/html/.env', '');
foreach ($_ENV as $key => $value)
{
if (
strpos($key, 'PHP_') === 0 ||
strpos($key, 'NOTIFY_') === 0 ||
strpos($key, 'HTTP_') === 0 ||
strpos($key, 'SCRIPT_') === 0 ||
strpos($key, 'SERVER_') === 0 ||
strpos($key, 'GATEWAY_') === 0 ||
strpos($key, 'REQUEST_') === 0 ||
strpos($key, 'DOCUMENT_') === 0 ||
strpos($key, 'FCGI_') === 0 ||
strpos($key, 'REMOTE_') === 0 ||
strpos($key, 'PATH_') === 0 ||
strpos($key, 'CONTENT_') === 0 ||
strpos($key, 'QUERY_') === 0 ||
strpos($key, 'REDIRECT_') === 0 ||
$key === 'USER' || $key === 'HOME' || $key === 'LANG'
|| $key === 'PATH'
)
{
continue;
}
file_put_contents('/var/www/html/.env', $key.'='.$value."\n", FILE_APPEND);
}
echo 'DONE';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment