Created
July 13, 2023 03:17
-
-
Save u007/b76f1e121d2dcf612b9e86bd190f100d to your computer and use it in GitHub Desktop.
php code to generate .env from elasticbeanstalk environment variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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