Laravel artisan always thinks its in local

2019-09-07 22:10发布

问题:

I set several ENV variables with Laravel Forge which are correctly picked up by the application. However artisan doesn't seem to pick up my environment. php artisan env returns:

Current application environment: local

In the nginx configuration I also have

fastcgi_param ENV "test";

This is how I detect my environment:

$env = $app->detectEnvironment(function () {
    return getenv('ENV') ?: 'local';
});

How can I have artisan think its in the test environment?

回答1:

Go to your laravel forge site and click on 'Edit Deploy Script'.

Change line 4 to

php artisan migrate --env=production

or whatever env you need.

You will need to do the same when running an artisan command in the console.

php artisan <command> --env=test


回答2:

Try to verify if your .env file is correctly configured. Take a look in your .env and set this:

APP_ENV=test

after that try to clear your configuration. Type this in your terminal:

php artisan config:clear

and to finish verify your environment with this:

php artisan env

I hope this help you.

Regards!