3

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.envwith 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.

  • You've tagged your question as `laravel-5.1`, but your code doesn't work in 5.1. It would throw an error, since `detectEnvironment` [expects a closure](https://github.com/laravel/framework/blob/cbf68c02542e3d668086283c1928347d1e6f605f/src/Illuminate/Foundation/Application.php#L470). – Joseph Silber Oct 04 '15 at 15:20
  • I followed this tutorial - http://stackoverflow.com/questions/31082173/laravel-5-environment-detection, before posting this, and it returns as `Call to a member function detectEnvironment() on null` error. –  Oct 04 '15 at 15:25

5 Answers5

12

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

Jose Celano
  • 539
  • 1
  • 7
  • 14
  • This seems to work. I'm still baffled as to where "production" was coming from before I added this line...? – thesunneversets May 11 '16 at 11:36
  • 1
    Ran into this issue in laravel 5.4. It's due to the fact that i've upgraded from 5.1 to 5.4 directly from `composer update`, and missed this upgrade instruction on the laravel website. – Mysteryos Jul 27 '17 at 15:34
2

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.

Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • Yes, I initially read the docs, but for multiple environments like I'm trying to set up, it's not particularly detailed - specifically into how you can specify your `local` and `production` names. –  Oct 04 '15 at 15:30
  • Do you have any guidance on how to detect multiple environments please? –  Oct 04 '15 at 15:36
  • Again, there's no need to set up multiple environments. You just change the actual values in your `.env` file on every server. – Joseph Silber Oct 04 '15 at 15:39
  • But how can Laravel detect whether to use my local one because I'm on my laptop, or the production one because it's live? –  Oct 04 '15 at 15:43
  • Again, only use one single file. On your local machine that file will have the information you need for your local environment. On your production machine, that file will have the information you need for your production environment. – Joseph Silber Oct 04 '15 at 16:31
1

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, e.g. .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.

Gaz
  • 1,570
  • 2
  • 17
  • 22
1

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!

0

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
General Grievance
  • 4,555
  • 31
  • 31
  • 45