29 lines
1.2 KiB
PHP
29 lines
1.2 KiB
PHP
<?php
|
|
|
|
use App\Ops\Environment;
|
|
use Symfony\Component\Dotenv\Dotenv;
|
|
|
|
require dirname(__DIR__).'/vendor/autoload.php';
|
|
$root = dirname(__DIR__);
|
|
Environment::prepare($root);
|
|
// Server variables are explicit deployment overrides; other .env.* files are never loaded.
|
|
$keys = array_keys((new Dotenv())->parse((string) file_get_contents($root.'/.env')));
|
|
foreach (array_unique([...$keys, 'APP_ENV', 'APP_DEBUG', 'APP_SECRET', 'DATABASE_URL', 'SITE_ORIGIN', 'MEDIA_DIRECTORY', 'ADMIN_PATH', 'FONT_DIRECTORY', 'ASSET_DIRECTORY']) as $name) {
|
|
$value = getenv($name, true);
|
|
if (false !== $value && !isset($_SERVER[$name]) && !isset($_ENV[$name])) {
|
|
$_SERVER[$name] = $_ENV[$name] = $value;
|
|
}
|
|
}
|
|
(new Dotenv())->load($root.'/.env');
|
|
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $_SERVER['APP_ENV'] ?? 'prod';
|
|
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? '0';
|
|
if ('' === ($_SERVER['APP_SECRET'] ?? '')) {
|
|
try {
|
|
$secret = Environment::ensureSecret($root);
|
|
} catch (RuntimeException) {
|
|
// Keep the installer reachable: its system check names the missing permission.
|
|
$secret = bin2hex(random_bytes(32)).'-nicht-gespeichert';
|
|
}
|
|
$_SERVER['APP_SECRET'] = $_ENV['APP_SECRET'] = $secret;
|
|
}
|