Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getenv return false after laravel 5.8 update #27913

Closed
svikramjeet opened this issue Mar 18, 2019 · 10 comments
Closed

getenv return false after laravel 5.8 update #27913

svikramjeet opened this issue Mar 18, 2019 · 10 comments

Comments

@svikramjeet
Copy link

svikramjeet commented Mar 18, 2019

  • Laravel Version: 5.8.4
  • PHP Version: 7.2.14
  • Database Driver: pgsql

Description:

If you print getenv after laravel 5.8 update it will return false.

Steps To Reproduce:

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

@driesvints
Copy link
Member

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 ?

@svikramjeet
Copy link
Author

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.

@seriquynh
Copy link
Contributor

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!

#27462
#27519

@svikramjeet
Copy link
Author

Thanks @XuanQuynh .

@AndyMac2508
Copy link

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])
        );
    }

@mfn
Copy link
Contributor

mfn commented Mar 21, 2019

@AndyMac2508 would you mind exposing the packages? Could be useful for others to learn about them before going to 5.8

@AndyMac2508
Copy link

the main one we had an issue with was https://github.com/aws/aws-sdk-php the other ones where internal packages we use.

@nomad-software
Copy link

nomad-software commented Mar 21, 2019

@taylorotwell I can't reply to you in the issue you replied to as it's been locked: #27949 (comment) but the fix for that issue is the same as this one, adding a single line as shown listed above here by @AndyMac2508

@driesvints
Copy link
Member

@nomad-software I've unlocked it again

@magarrent
Copy link

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 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants