Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set location of laravel .env

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?

like image 571
Sjoerd de Wit Avatar asked Dec 24 '22 07:12

Sjoerd de Wit


2 Answers

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)
);
like image 135
Aigars Matulis Avatar answered Dec 28 '22 09:12

Aigars Matulis


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.

like image 28
Stefano Ortisi Avatar answered Dec 28 '22 10:12

Stefano Ortisi