If you print getenv after laravel 5.8 update it will return false.
Upgrade laravel to 5.8.4
Edit /config/database.php
Add dd(getenv('DATABASE_URL')); in the database.php
This will print false whereas laravle5.7 was showing exact DB url in format:
database://username:password@host:port/database_name
How have you defined this in your .env file? Have you read the changes in https://laravel.com/docs/5.8/upgrade and https://github.com/vlucas/phpdotenv/blob/master/UPGRADING.md ?
driesvints : Yes DATABASE url is in .env as i haven't update .env file which was working fine in 5.7.I have gone through the changes as well but i haven't fountd any updates regarding getenv() as this is php method not laravel which i think should not be impacted while laravel upgrade.
Laravel 5.8 will only load environment variables into $_SERVER and $_ENV. It doesn't write into the computer system anymore. That is why the getenv function returns false this situation. It's a breaking change, not a bug.
Do not use the getenv PHP native function, use env helper instead!
https://github.com/laravel/framework/pull/27462
https://github.com/laravel/framework/pull/27519
Thanks @xuanquynh .
We have been experiencing the same issue while upgrading to 5.8 in our application, its not necessarily a problem with the Laravel application itself , but does break third party packages that use the native getenv() function. its broken most of the packages. We fixed it by altering the createDotenv
function in the LoadEnvironmentVariables class to look like the below
protected function createDotenv($app)
{
return Dotenv::create(
$app->environmentPath(),
$app->environmentFile(),
new DotenvFactory([new EnvConstAdapter, new ServerConstAdapter, new PutenvAdapter])
);
}
@AndyMac2508 would you mind exposing the packages? Could be useful for others to learn about them before going to 5.8
the main one we had an issue with was https://github.com/aws/aws-sdk-php the other ones where internal packages we use.
@taylorotwell I can't reply to you in the issue you replied to as it's been locked: https://github.com/laravel/framework/issues/27949#event-2220001966 but the fix for that issue is the same as this one, adding a single line as shown listed above here by @AndyMac2508
@nomad-software I've unlocked it again
In my case I run the php artisan optimize command before adding a env variable, and then the .env was cached. Simply I run php artisan cache:clear !!
Most helpful comment
We have been experiencing the same issue while upgrading to 5.8 in our application, its not necessarily a problem with the Laravel application itself , but does break third party packages that use the native getenv() function. its broken most of the packages. We fixed it by altering the
createDotenvfunction in the
LoadEnvironmentVariablesclass to look like the below