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

NickvdMeij's avatar

[PROBLEM] Environment variables and php artisan

I recently started using laravel homestead (2.0) for my development environment, but i encountered a problem. In my homestead.yaml file i setted my environment variables like so:

variables:
    - key: APP_ENV
      value: local

and in my bootstrap/start.php i do:

$env = $app->detectEnvironment(function(){

    return getenv('APP_ENV');

});

And this works fine in the browser. When i var_dump(getenv('APP_ENV')) i get local as response. However, when i do php artisan env, i get the following:

Current application environment: 

I also got my database variables like host and usernames as environment variables, but those arent set in php artisan neither. I've searched a while now and havent found any answer. Homestead should provision those variables, but it only does a small job of doing so. Am i doing something wrong? Please help because im kinda stuck atm...

0 likes
2 replies
bart's avatar

As a workaround you can add the environment option when calling artisan commands like so:

php artisan env --env=local
Artistan's avatar

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. In this case you use crontab with -l (login) and -c (string exec) * * * * bash -l -c "php artisan --env=custom ..."

.profile sourcing details.... https://superuser.com/a/892248/168712 bash -l -c details... https://stackoverflow.com/a/21895892/372215

Please or to participate in this conversation.