Set location of laravel .env

20,148

Solution 1

I ended up setting a symlink from public to public_html and everything worked as expected

Solution 2

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

Solution 3

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.

Solution 4

What you need to upload to public_html is contents of public directory in Laravel installation including any JavaScript files, CSS files or images that should be accessible to client, everything else should be placed out of public directory.

Share:
20,148
Sjoerd de Wit
Author by

Sjoerd de Wit

I build stuff with laravel, angular and ionic. Like to keep up with things in this world.

Updated on November 18, 2021

Comments

  • Sjoerd de Wit
    Sjoerd de Wit over 2 years

    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?