Support the ongoing development of Laravel.io →
Installation Configuration Database
Last updated 2 years ago.
0

You'd generally store your "sensitive" env vars in a .env.*.php file in your root, which are by default ignored by git for safety reasons. I.e. you create them on local machine and are than ignored when you do git push.

I don't have much experience with forge, but you should have a page where you can create your env vars that are than applied to laravel without actually saving them inside the project.

Last updated 2 years ago.
0

pogachar said:

You'd generally store your "sensitive" env vars in a .env.*.php file in your root, which are by default ignored by git for safety reasons. I.e. you create them on local machine and are than ignored when you do git push.

I don't have much experience with forge, but you should have a page where you can create your env vars that are than applied to laravel without actually saving them inside the project.

That's exactly right, I'm sing the Laravel Forge page which are generating correct .env.*.php files and the getenv are also correct. But the config doesn't seem to read the correct, I've no clue why,

Last updated 2 years ago.
0

I'm having the exact same problem, and I'm really keen for an answer. php artisan env returns the correct environment, and my app can use all the env vars fine, but artisan can't seem to read them properly, through commands, or Tinker. Desperately hope there's an answer for this soon, it's beyond frustrating. I reached out to Taylor, and he simply didn't know why. I'm glad someone else is getting this issue, so it might get some more attention.

Last updated 2 years ago.
0

Try changing to

'host'      => $_env['DB_HOST'],
'database'  => $_env['DB_NAME'],
'username'  => $_env['DB_USERNAME'],
'password'  => $_env['DB_PASSWORD'],

Watch the free series Server management with Forge on Laracasts.

Last updated 2 years ago.
0

syropian said:

I'm having the exact same problem, and I'm really keen for an answer. php artisan env returns the correct environment, and my app can use all the env vars fine, but artisan can't seem to read them properly, through commands, or Tinker. Desperately hope there's an answer for this soon, it's beyond frustrating. I reached out to Taylor, and he simply didn't know why. I'm glad someone else is getting this issue, so it might get some more attention.

It's really frustrating indeed,

pogachar said:

Try changing to

'host'      => $_env['DB_HOST'],
'database'  => $_env['DB_NAME'],
'username'  => $_env['DB_USERNAME'],
'password'  => $_env['DB_PASSWORD'],

Watch the free series Server management with Forge on Laracasts.

I tried a var_dump of $_ENV. I can only see the DB_NAME with that. So something is completly borken I guess. :) I'll try to research it further and return with an answer I hope.

I've watched that serie on Laracasts and that's the reason why I first got in touch with Homestead and Forge, really good serie, indeed! :)

Last updated 2 years ago.
0
Solution

I found an answer in my post at Stack Overflow. I don't know why there's an error but it seems like If you're writing production in the environment field at Forge it won't work so skip to write anything in that field and It will work.

The solution is quoted as this: Make sure you're env file is called .env.php and not .env.production.php. I made this mistake, and although having .env.production.php will work in app, it won't when using Artisan.

When creating env vars within Forge, if it's for a production environment, be sure to leave the environment field blank, as opposed to explicitly setting it to production.

Last updated 2 years ago.
0

Oops, forgot to ping you on here when I answered on SO. Glad it's working for you too :)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

murum murum Joined 7 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.