ben.IT
ben.IT

Reputation: 1610

How to set up a staging environment based on a symlink to prod configuration, without showing debug information?

I would like to setup a staging environment with the same configuration as the prod environment.

According to the docs, I proceed as follow:

I create a staging symlink that points on prod

When the APP_ENV=prod, my custom error page is render properly, but when APP_ENV=staging, the debug message NotFoundHttpException is rendered? The profiler is not displayed.

What am I missing?

Upvotes: 1

Views: 530

Answers (1)

yivi
yivi

Reputation: 47308

tldr;

Crate an .env.staging file and use it to set APP_DEBUG to 0. Debug mode and environment are set independently.


By default, unless you set it explicitly debug mode (APP_DEBUG) is set from the environment automagically.

This happens in the following steps:

In your front-controller (index.php, usually) you would find this line:

(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');

And on DotEnv::bootEnv() you'll find this:

$debug = $_SERVER[$k] ?? !\in_array($_SERVER[$this->envKey], $this->prodEnvs, true);

This will compare your APP_ENV with an array of "environments" that DotEnv, considers "production-like". By default, this array includes only prod.

You could modify the instance of the DotEnv by calling setProdEnvs():

(new Dotenv())
    ->setProdEnvs(['prod', 'staging'])
    ->bootEnv(dirname(__DIR__).'/.env');

... but generally simply disabling debug mode on your .env file would be enough.

Upvotes: 2

Related Questions