Support the ongoing development of Laravel.io →
Configuration
Last updated 1 year ago.
0

I don't use environment variables a lot, but According to the PHP docs, it looks like anything in the $ENV superglobal has to start with "PHP", so in order to access it via $_ENV you may need to call it "PHP_database_host".

Last updated 1 year ago.
0

Well the $_ENV does work if you have a .env.xxx.php file, it just doesnt seem to come further if you use a virtualhost for it. $SERVER is also a superglobal, if i call that instead it works just fine. But i want to keep the code the same and use $_ENV everywhere instead of having this one setup use something else.

Last updated 1 year ago.
0

Why not use something like this?

'host' => (getenv('database_host') !== false) ? getenv('database_host') : 'localhost',
Last updated 1 year ago.
0

Duh, should have thought of that. I got it working now. So now i dont need a .env.xxxx.php file.. only to find out that if you run your migrations it will not use the virtualhost and cannot set the values.

Anyways the reason is when i publish my stuff to prod i first clean the directory where it goes to. This also deletes my .env.xxx.php file so i wanted a sollution that would stick when wiped.

Last updated 1 year ago.
0

I'll mark above as solution from thepsion, since that was the question. But i did find another solution, its a bit cheezy but hey some solutions are. I just chmod 444 the .env.xxx.php file, so it doesn't get deleted but still works.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Snelvuur snelvuur Joined 18 Feb 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.