I'm noticing this too. A vagrant reload --provision doesnt work either. Any insight on this would be appriciated.
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?
You just pull from laravel/laravel last commits? Use instead (for now) your .env file in the root directory of the project. Add to your .env file the following:
APP_ENV=custom
and
APP_DEBUG=yes
https://github.com/laravel/laravel/commit/430134864642346498631ad562765d69599d6b39
Can we just delete variables from Homestead.yaml?
@jrean No, I haven't pulled the bleeding edge commits, still riding v4.2.11 which Composer gives me.
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
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.
Ok great ; But now, if you change APP_ENV to "FOO" for testing ... Then perform a vagrant reload, does the change is applied?
@jrean, that doesn't work, i tried that many times.
@heihachi88 what doesn't work? The above commands I asked to perform or the change I asked after @lasseal trick/fix?
Changing APP_ENV to "FOO" then vagrant reload or vagrant reload --provision didn't work.
That means it is not reflecting your APP_ENV changes... Hum, weird. Just for testings again, if you drop and stop setting ENV trough your Homestead.yml but instead directly within a .env file as documented here: http://laravel.com/docs/4.2/configuration#protecting-sensitive-configuration
Does your changes are reflected and work?
.env:
APP_ENV=haha
var_dump(getenv('APP_ENV'):
"local"
Seems like "local" is hardcoded somewhere in homestead.
[This answer is ONLY working for Laravel 4.x (not for Laravel ~5.0)]
Yes because you are running from homestead.
https://github.com/laravel/laravel/blob/master/bootstrap/start.php
You have to tweak the detection method :)
For example:
$env = $app->detectEnvironment(function()
{
return getenv('APP_ENV') ?: 'local';
});
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.
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'),
));
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.
And by the way bootstrap/environment.php has been removed.
So we only work with .env file and key/value.
We don't care about detection method anymore. See Taylor comment and commit.
https://github.com/laravel/laravel/commit/430134864642346498631ad562765d69599d6b39
Homestead uses APP_ENV in Homestead.yaml, not in .env
@heihachi88, just throw that out and use .env as your only place to define APP_ENV (and also APP_DEBUG).
@rawfan is right. It's what I advised @heihachi88 in a previous post (page 1)
I was having the same problem, and eventually solved it in the following way:
-
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.
-
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.
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?
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.
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
@pixelpeter thank you. Removing the variables block from my homestead.yaml file is what I needed in addition to commenting out APP_ENV=local
homestead uses zsh now, and that does not source the .profile script that bash does by default. Without that sourced, the ENV variable is not set for the user. Note, this maybe an issue with manual crons also. Use php artisan --env=custom ...
https://superuser.com/a/892248/168712
Posted a pull request to fix the current version of homestead settler box build. https://github.com/laravel/settler/pull/133
Please or to participate in this conversation.