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

AlexanderKim's avatar

Homestead APP ENV not working

Changing Homestead.yaml:

variables:
    - key: APP_ENV
      value: custom

then vagrant reload

php artisan env shows "production"

but var_dump(getenv('APP_ENV') in index.php shows "local", though i've set "custom" in my Homestead.yaml.

What's wrong?

0 likes
27 replies
lasse's avatar

I'm noticing this too. A vagrant reload --provision doesnt work either. Any insight on this would be appriciated.

lasse's avatar

@jrean No, I haven't pulled the bleeding edge commits, still riding v4.2.11 which Composer gives me.

jrean's avatar

Ah ok, sorry. What is the version you use?

vagrant -v
vagrant box list laravel/homestead

It should be "laravel/homestead (virtualbox, 0.2.0)"

If not, update the box

vagrant box update --box laravel/homestead
vagrant reload --provision
lasse's avatar

Im on 0.2.0, vagrant reload or vagrant reload --provisionneither reloads the APP_ENV but a vagrant destroy and vagrant up fixes it, but shouldn't really be necessary.

jrean's avatar

Ok great ; But now, if you change APP_ENV to "FOO" for testing ... Then perform a vagrant reload, does the change is applied?

AlexanderKim's avatar

@jrean

Changing APP_ENV to "FOO" then vagrant reload or vagrant reload --provision didn't work.

AlexanderKim's avatar

.env:

APP_ENV=haha

var_dump(getenv('APP_ENV'):

"local"

Seems like "local" is hardcoded somewhere in homestead.

1 like
lasse's avatar

I'm running

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

but still it doesn't pick up any changes to APP_ENV in homestead.yaml.

AlexanderKim's avatar

@jrean

It's an outdated code, bro. I don't have this in bootstrap/start.php (I am using Laravel 5 "develop" branch)

$env = $app->detectEnvironment(array(
'local' => array('homestead'),
));
jrean's avatar

I based my answers to @lasseal saying 4.2 sorry!!

"No, I haven't pulled the bleeding edge commits, still riding v4.2.11 which Composer gives me."

So simply use a .env file and put APP_ENV=local or whatever you want.

rawfan's avatar

@heihachi88, just throw that out and use .env as your only place to define APP_ENV (and also APP_DEBUG).

1 like
ballistic101's avatar

I was having the same problem, and eventually solved it in the following way:

  1. As stated above, there was an entry in Homestead.yaml for APP_ENV. I got rid of those as the posts above say, but that did not resolve the problem.

  2. I found in homestead: /etc/php5/fpm/php-fpm.conf there are two lines at the bottom which say: env[APP_ENV] = 'local'

I commented them out, then ran: sudo service php5-fpm restart

That resolved the issue and now APP_ENV is getting the proper value.

For the record, this all comes about because the Dotenv module is run in "immutable" mode, so the pre-existing variable (in $_SERVER) does not get overwritten.

1 like
spar_x's avatar

I am having pretty much the same problem but it is not related to the APP_ENV key.

I set another variable in my homestead.yaml called "HOME". I set it to XXX, and then later changed it to YYY.. and doing either vagrant reload or vagrant reload --provision refuses to update the variable to YYY. It is stuck on XXX and it does not want to get updated. This is very problematic that values get stuck like that and refused to get changed.. even custom variables!!! I don't want to have to destroy my box as I have lots of mysql databases installed and configured inside my homestead VM.

Has anyone figured out this riddle?

spar_x's avatar

I thought I had found the culprit.. or maybe I did. I noticed that every time you do a reload --provision it appends your environment variables to the ~/.profile inside your homestead.

I had dozens these in my .profile file

#Set Homestead environment variable export APP_ENV=local

Same thing for my "HOME" variable and a new "TEST" variable I created to see if I could reproduce this issue of environment variables getting stuck on old values. I was able to reproduce it. However after deleting all the entries inside .profile and doing another reload --provision (as well as a combination of source .profile and service php-fpm restart). I still can't get getenv("HOME") to show my new value.

From the CLI if I do a echo $HOME it does show my updated value! And from the cli if I run "set" I can see that HOME is indeed set to the new value. However running getenv("HOME") from a php script refuses to use the new value. It is somehow holding on to the very first value I set on HOME a while ago. As if getenv is caching... this is really frustrating... but hopefully my findings will help narrow the cause of this problem.

I will report back if I ever do find the real culprit.

pixelpeter's avatar

with Laravel v5.1.17, Vagrant 1.7.2, Homestead 0.2.7 I needed to combine the given tips: I removed APP_ENV=local from /etc/php5/fpm/php-fpm.conf and removed the complete variables block from homestead.yaml

variables:
    - key: APP_ENV
      value: local

After vagrant --provision , /etc/init.d/php5-fpm restart and sudo /etc/init.d/nginx reload the environment was finally taken from the .env file

RobFrancken's avatar

@pixelpeter thank you. Removing the variables block from my homestead.yaml file is what I needed in addition to commenting out APP_ENV=local

Please or to participate in this conversation.