Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ATOM-Group's avatar

@cskiwi, when you changed APP_ENV to Glennlocal in homestead.yml, did you rebuild your environment after, or did you change that value before building the environment?

AlexanderKim's avatar

Changed APP_ENV value in Homestead.yaml to production. But getenv('APP_ENV'); still returns local.

Also did vagrant reload

ATOM-Group's avatar

Yep, that sounds like a pretty nasty Homestead bug. Out of curiosity, if in a plain php file somewhere in homstead you do putenv("APP_ENV=production") and then immediately var_dump(getenv('APP_ENV')), what happens?

zgames's avatar

I have the same problem, but mine doesn't use config/local it uses the production config settngs, I have set .env variable to local, homestead key is local also, on terminal it says production, var dump gives me local. Anyone solved this problem?

JasperK's avatar

Same here for Laravel 4.2. Even when trying to add new variables, they aren't recognized in the detectEnvironment()-part in start.php. When I dump the getenv('VARNAME') on top of the same file, it does return the correct value.

ceesco53's avatar

This issue is happening here - and I've updated to latest Laravel 5. var_dump(getenv('APP_ENV')) in testing/database.php shows I'm running local, but the testing database file get loaded anyways. I've got a workaround in place by using conditional statements in testing/database.php, but I don't really like doing that. Maybe my Laravel 5 is screwy, but I'm not finding any evidence of that since everything functions normally with my conditional statement in place (forcing local/database.php to load).

Looks like testing files/subdirectory are loading no matter what I do with APP_ENV. Same series of workarounds required when I set APP_ENV to production, just like the OP stated.

here is my simple example in testing/database.php:

if ($_ENV['APP_ENV'] == 'production') {
    // return production database settings array
}

if ($_ENV['APP_ENV'] == 'local') {
    // return local database settings array
}

// else return testing settings array
  • Using fresh homestead 0.2.2
  • Don't think it is a homestead bug since APP_ENV isn't getting set until the $kernel->handle() call in index.php
pmall's avatar

There is no more notion of subdirectories in the config folder anymore. Remove them all.

Then for example for the db hostname, it takes the value set in .env and if there is no value set it fallback to a default value.

Look for example config/queue.php

'driver' => env('QUEUE_DRIVER', 'sync')

Dont know how it works for testing env.

ceesco53's avatar

I'm holding off on testing for now. I think it is somewhat of a waste right now to deal with testing when I'm coping with all the L5 changes. @pmall, using that example, I went ahead and modified .env with a new line:

DB_DRIVER=mysql

Then I tweaked config/database.php (should be like this anyways to match config/queue.php style):

    'default' => env('DB_DRIVER', 'mysql'),

This solves my problem with the environment, and easily can be tweaked for testing, local, or whatever.

EDIT: pull request already exists for this - https://github.com/laravel/laravel/pull/3208

fulup's avatar

I"m still in development phase, but I noted that L5 now takes config files from directory in alphabetic order. If I have a-config/app.php it will be taken before b-config/app.php and this independently from what is written in .env file.

I'm under Linux and did not update since few week my L5 distrib as each 'composer update' break it.

web-chiru's avatar

Hi All,

I am facing the same issue. I install fresh larval 5.0.16 via composer on mac MAMP stack. now when i try to change APP_ENV value to testing or production instead default to local and try to print using dd(env('APP_ENV')); then it gives me local only. i have removed all content from .env file and still it returns local. in the terminal when i type "php artisan env" then it gives me whatever value i set to from .env file . So, i am not sure why it takes local always and debug value to true always. Can jefferey or any other can help in this matter. thanks in advance...

1 like
pinkal-vansia's avatar

I faced the same issue today. I simply cloned my Laravel 5.0.27 app from bitbucket ( .env.example is ignored in .gitignore). There was no .env.example in my project root folder. Then I did things like 'composer install'. When I ran 'php artisan migrate' it warned me if I want to migrate in 'production' environment. Then, I realize I didn't create .env. I went ahead and created .env file with 'APP_ENV' set to local. But It was having no effect on my application. I placed following two lines in routes.php,

var_dump(getenv('APP_ENV')); // output  =>  false
dd(\App::environment()); // output => production

I was clueless. I cleared cache and everything. But after debugging I realized that following condition on line no. 25 in 'vendor/vlucas/phpdotenv/src/Dotenv.php' was evaluating true, my file was not readable.

if (!is_readable($filePath) || !is_file($filePath)) {

I fired,

sudo chmod -R 777 .env

and voila, it started working again.

pmall's avatar

.env.example is ignored in .gitignore

It shouldn't. It is an example of environment configuration with dummy values. You you just have to cp .env.example .env and put the actual values to get a working configuration.

pinkal-vansia's avatar

@pmall You are absolutely right. In initial stage of my project I did not commit .env.example in repository. Hence, While cloning project on new system , I do not get .env.example. It was my mistake. But I will add it to my repository. So in future, on new system, after running composer install, it will automatically get copied to .env file with "post-create-project-cmd" command and this issue of wrong environment would never arise. Thanks.

maltos's avatar

If you are using homestead and you are trying to modify the environment value change your homestead.yaml to

variables:
  - key: APP_ENV
  - value: new_env_name

and then provision

vagrant global-status
vagrant provision YourHomesteadIdNumer

But if you want to force laravel to use APP_ENV defined inside the .env, then you need to remove that variable from the homestead.yml and run the provision command again... but must important. If you remove the variable, homestead keeps the variable definition, actually each time you change it, it just add a new line in the .profile file but does not remove the old.

So access your homestead in your project folder and remove all references to this variable.

homestead ssh
cd .
nano .profile

Then set the APP_ENV inside the .env file, refresh the config cache and run artisan to see its value..

php artisan config:cache
php artisan env

You should get the APP_ENV from the .env configuration file

1 like
ben_s247's avatar

Hmm this problem seems to be caused by the cache. just run php artisan cache:clear and you should see the new configuration settings work. remember laraval caches your pages to give you a faster response this isn't great for development so it's wise to leave them not cached while developing.

patoui's avatar

Not sure if people are still having issues with this.

  • using Homestead
  • no variables declared in my homestead.yaml
  • .env in the project root directory with APP_ENV=local

Issue: php artisan env displayed production while var_dump(getenv('APP_ENV')); exit(); in public/index.php displayed local

To fix this I had to add the following to my config/app.php:

 'env' => env('APP_ENV', 'production'),
1 like
Gompje's avatar

@patoui thanks for sharing your solution! Just converted a project to 5.3 from 5.1 this week with the upgrade guide and somehow I must have miss that this config setting must now be added to the app.config (or it wasn't in there). Was hunting for some weird cache issues - blaming the server/browser and what not - all the while the app was just running in the wrong mode! Thx!

Previous

Please or to participate in this conversation.