So I just published a build of laravel to my production server. But the .env file was readable when I uploaded it. So I uploaded it to root of my site next to the public_html/
directory.
My question is: How to tell laravel where the .env
file is located? It worked when I had it in the public_html/
folder but how do I tell it to look in the root folder?
Set env path in bootstrap/app.php:
$app->useEnvironmentPath($env_path);
for example, directory layout for my project:
webapp
-laravel
-public
-.env
Custom path to env file
$app->useEnvironmentPath(
dirname(__DIR__, 2)
);
As you can read in the official documentation, the .env file must be in the root directory of your Laravel app. There's no way to change the file location (and I think there's no point too).
Moreover, the root folder SHOULDN'T be a public folder, as .env shouldn't be exposed to a public access, otherwise the main security aim of it would be completely lost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With