简体   繁体   中英

Laravel 5 environment is always 'Production' when it is infact 'Local'

I am trying to set up two environments: local and production.

So far, I have added a bootstrap/environment.php file which is:

$env = $app->detectEnvironment(array(
    'local' => array('Ben'),
    'staging' => array('staging.domain.org'),
    'production' => array('domain.org'),
));

and two .env files - .local.env and .production.env with the different environment variables such as: APP_ENV=local and APP_DEBUG=true .

My laptop's hostname is called Ben .

The problem I'm having is the php artisan env always returns Production and thus, I can't load my application.

Also, within the production.env file, if I change the APP_DEBUG variable to true or false, it doesn't make a difference on the web application - it always returns "Whoops, looks like something went wrong.".

Any help would be greatly appreciated. Thank you.

I had that problem. I am using Laravel 5.2.14 with homestead. I fixed the problem adding this line:

'env' => env('APP_ENV', 'production'),

in the file: config\\app.php

I upgraded my Laravel app from a previous version which did not contain that line or at least I did not have it. Latest file version in:

https://github.com/laravel/laravel/blob/master/config/app.php

The bootstrap/environment.php file is not loaded in Laravel 5.1 anymore. Laravel does not load different env files depending on the environment.

Laravel now only loads a single .env file. This file should not be in your version control. For your production server, you'll simply put different values into the .env file.


For more information, read the docs .

This bugged the hell out of me in Laravel 5. The way I fixed it was by adding the following to the end of bootstrap/app.php:

    $app->detectEnvironment(function () use($app) {
        $env = env('APP_ENV', 'local');
        $file = ".env.{$env}";
        $app->loadEnvironmentFrom($file);
    });

Then add files for each environment, eg .env.local, .env.production etc.

You can now swicth environment files by setting the APP_ENV environment variable. The code defaults to '.env.local' if APP_ENV is not set. Test this works with:

    $ APP_ENV=production ./artisan env
    Current application environment: production

    $ ./artisan env
    Current application environment: local

Laravel automatically sets APP_ENV to 'testing' when running phpunit (specifically in the Foundation/Testing/TestCase class), so make sure you have a '.env.testing' file if you want to use different database settings etc when running tests.

For Laravel >= 5.1

It's because your environment is configured wrong or your .env file was not correctly set.
Try this

php artisan config:clear

Maybe that help you.

Regards!

Go to your .env file in laravel and set your

PAYTM_ENVIRONMENT=production

PAYTM_MERCHANT_ID={// Your production MID}

PAYTM_MERCHANT_KEY={// Your production Merchant key}

PAYTM_MERCHANT_WEBSITE=DEFAULT

PAYTM_CHANNEL=WEB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM