It doesn't use hostname any more.
Make a .env file in root dir and include something like this in the file
APP_ENV=local
DB_HOST=localhost
DB_USERNAME=username
etc
etc
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am on a localhost (using homestead). When i run:
php artisan env
i get production, but if it's production why it does use my "config/local/database.php" settings for connecting to a database? Laravel detects my environment by a hostname? If yes, why it shows "production" then? If i have localhost hostname.
I misunderstand the concept of environments and local folder configs.
It doesn't use hostname any more.
Make a .env file in root dir and include something like this in the file
APP_ENV=local
DB_HOST=localhost
DB_USERNAME=username
etc
etc
@bashy, but if i have no .env file, it will be using "production" by default. If it's "production" then why it uses "config/local/database.php" and not "config/database.php"? Which seems logical to me.
You sure it's using that file? Haven't had that happen before...
Yes, i am sure that it's using "config/local/database.php" because i've set db_name and db_password there and in "config/database.php" there's default values.
That won't help if production env is using config/local/database.php..........................
Edit: Okay, delete your reply fenos :)
@fenos, the question is about why it's using "config/local/database.php" in production environment?
@bashy et. all
Note there is a "bug" with respect to changing your .env file
https://github.com/laravel/framework/issues/6096
Basically if APP_ENV is already set, by default the Dotenv class will not change it, as it's immutable by default. You need to add Dotenv::makeMutable() above Dotenv::load() in your bootstrap\environment.php file in order to make it so that your .env file changes actually take effect.
@bashy yes i deleted my reply because i understand that i said a stupid thing i miss understand the question sorry :p
Added to bootstrap/environment.php:
if (file_exists(__DIR__.'/../.env'))
{
Dotenv::makeMutable();
Dotenv::load(__DIR__.'/../');
//Dotenv::required('APP_ENV');
}
Now tried to save a page in to DB and it got saved which means it doesn't work :D
Laravel still uses local config.
@heihachi88 you did mv .env.example to .env, as well right?
I had
.env.example
and created
.env file with
APP_ENV=local
then deleted that .env file and it still shows "production" environment.
It's like caching it I guess. Least we got somewhere :)
I have had the exact same issue where even in a homestead virtual env it just won't set my local env if i use laravel 5. I have tried:
1. export=APP_ENV (in my vm terminal)
2. Rename .env.example to .env
3. Added an fastcgi_param with the fallowing: APP_ENV "local" (that did set an $_SERVER global but i cannot get that to an $_ENV veriable.
First when i removed the default of production to local it worked this is an very strange issue.
then deleted that .env file and it still shows "production" environment.
So just to recap the original issue:
Your environment says "production", but your database configuration is being loaded from config/local/database.php?
I'm wondering if the php artisan env command is not working correctly.
Try this:
Somwhere in your routes.php file (if you have one) or any service provider, place these two lines.
var_dump(getenv('APP_ENV'));
dd(\App::environment());
Take note of what it shows in the browser, and then immediately run php artisan env.
All three should be the same.
If you have not previously set the environment variable, then by default all three should be 'production'. If you have a .env file with APP_ENV=local, then all three should be 'local'.
If some are production while others are local, then I'm betting there's a bug somewhere and thus the 'local' folder is being used rather than the production folder, even though it LOOKS like your environment is production.
Also note that php artisan --env affects ONLY the command line environment for all subsequent requests. It could be that php artisan env is also showing only the command line environment settings as well, thus for HTTP requests you are actually in 'local', but artisan environment is showing 'production'.
Your environment says "production", but your database configuration is being loaded from config/local/database.php?
Somwhere in your routes.php file (if you have one) or any service provider, place these two lines.
php artisan env shows "production". Why it's local? I don't have an .env file with APP_ENV set to local?Alright, interesting. I would go all the way to the index.php in the /public directory and var_dump(getenv('APP_ENV')); at the very top to see if it's being set to local before any Laravel code is executed. What could be happening is either your Ngnix or Apache installation has that environment variable set somewhere in the .htaccess file or a .conf file - essentially being set outside of Laravel.
Alright, interesting. I would go all the way to the index.php in the /public directory and var_dump(getenv('APP_ENV')); at the very top to see if it's being set to local before any Laravel code is executed.
What could be happening is either your Ngnix or Apache installation has that environment variable set somewhere in the .htaccess file or a .conf file - essentially being set outside of Laravel.
using Nginx with php-fpm and there's no environment variable set in nginx.conf
even if i create .env file with APP_ENV=production i am getting "local" environment by using:
var_dump(getenv('APP_ENV'));
dd(\App::environment());
UPDATE 1.
Even on a fresh L5 install on a different VPS with nginx php-fpm i am getting "local" environment when using:
var_dump(getenv('APP_ENV'));
at the top of index.php and in terminal i am getting "production" wtf.. :D
Once you go local, you never go back!
@bashy, have you tested that behavior on L5?
I have an old version of Laravel 5 running for messing about and I've just tested it. I changed the value in .env after the first command
~/Sites/testing(branch:dev*) » artisan env
Current application environment: local
------------------------------------------------------------
~/Sites/testing(branch:dev*) » artisan env
Current application environment: production
Can you update to a latest dev-build?
And try in index.php:
var_dump(getenv('APP_ENV'));
If I did it would all break from the updates. I'll try on a fresh install instead.
Edit - Okay, on new install - changing value in .env file changes env and also switches file used between config/local/app.php and config/app.php (I see whoops error on missing route).
Well, php artisan env shows the information depends on APP_ENV if it doesn't set it shows production by default.
But what shows var_dump(getenv('APP_ENV')); ?
UPDATE.
Again did a fresh L5 installation and var_dump(getenv('APP_ENV'));
shows "local" even if i create .env with APP_ENV=production
So it's a bug.
Again did a fresh L5 installation and var_dump(getenv('APP_ENV')); shows "local" even if i create .env with APP_ENV=production
Did you remember to put the Dotenv::makeMutable() call before the load() method?
Also, try creating a blank index.php file in another folder that is still being served by Ngnix, but not related to Laravel at all. Do the same var_dump(getenv('APP_ENV')); and tell me what you get. If you're getting anything, then Ngnix or maybe php.ini is setting that variable on you somewhere.
If you're getting anything, then Ngnix or maybe php.ini is setting that variable on you somewhere.
Just tried on a plain index.php and it returns "local". I am using Homestead... Could you please try the same on a homestead?
getenv('APP_ENV') was returning local/production when I switched it in the file. It also didn't use the config/local/app.php file when on production.
P.s I don't personally use Homestead because it's more trouble than it's worth :)
Thanks! What do you use for local development? Just VM with vanilla nginx/apache?
Very weird issue you're having though... not sure what else to suggest!
I pull in my own PHP/Nginx version locally on my Mac. Just prefer to and I know my way around it so it easy enough for me to manage different versions etc.
I'm also getting this error
Setting in .env:
APP_ENV=Glennlocal
Settings in homestead.yaml:
variables:
- key: APP_ENV
value: Glennlocal
Following commands give me local
var_dump(getenv('APP_ENV'));
dd(\App::environment());
but php artisan env gives me Glennlocal
Please or to participate in this conversation.