vlucas / phpdotenv

Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
BSD 3-Clause "New" or "Revised" License
13.17k stars 629 forks source link

Unable to read any of the environment file(s) #345

Closed deniskulygin closed 5 years ago

deniskulygin commented 5 years ago

Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [C:\xampp\htdocs\homework\public.env]. in C:\xampp\htdocs\homework\vendor\vlucas\phpdotenv\src\Loader.php:133 Stack trace: #0 C:\xampp\htdocs\homework\vendor\vlucas\phpdotenv\src\Loader.php(91): Dotenv\Loader::findAndRead(Array) #1 C:\xampp\htdocs\homework\vendor\vlucas\phpdotenv\src\Dotenv.php(123): Dotenv\Loader->load() #2 C:\xampp\htdocs\homework\vendor\vlucas\phpdotenv\src\Dotenv.php(80): Dotenv\Dotenv->loadData() #3 C:\xampp\htdocs\homework\public\index.php(8): Dotenv\Dotenv->load() #4 {main} thrown in C:\xampp\htdocs\homework\vendor\vlucas\phpdotenv\src\Loader.php on line 133

deniskulygin commented 5 years ago

I`ve solved it. Just change the path to .env file.

Thank you for your service! :)

torressam333 commented 5 years ago

@deniskulygin What path did you change?

Thanks.

deniskulygin commented 5 years ago

You have to use getenv() function to get needed .env variable. The .env file must be in the root of your project and use Composer Autoloader( /vendor/autoload.php) for correct work. To tell the truth, I don't remember what exactly was my problem, but, if you haven`t solved your problem yet, I can help you via TeamViewer.

mhysh33 commented 5 years ago

@torressam333 try save file as all files not as text.

mohit-in commented 5 years ago

TeamViewer

I stuck in same issue. can you help me to fix it

Rodr-Igo commented 4 years ago

I have the same issue and really dont know what is wrong with my code, I belive that might something with the composer... Can someone help me to fix it plz

KipchirchirIan commented 4 years ago

I know this is late but I had the same issue and I simply named the file to ".env" NOT config.env, var.env e.t.c. From there now you just have to specify the path. I have the .env file at the root of my project and am using the Slim framework. As you know how this frameworks work/how directories are structured, people usually have a public sub-folder and an index.php file inside it which serves as the entry point to the application. If this is the case(mostly Laravel, Symfony e.t.c.) then you just need to get the location of .env file correctly e.g.

$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__ . '/../');

If it's in public, this suffices:

$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__);

mishakansal commented 4 years ago

@deniskulygin how you fixed this issue?? can you please help me as im getting same.

Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [C:\wamp64\www\ProServices.env]. in C:\wamp64\www\ProServices\application\vendor\vlucas\phpdotenv\src\Loader.php on line 133

KipchirchirIan commented 4 years ago

@mishakansal Make sure you have the file at the said path, in your case, [C:\wamp64\www\]. Next step, rename the file to just .env and NOT Proservices.env. No text should precede the file extension.

Shumeza commented 4 years ago

Got this error..pls help me in finding the solution

PHP Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read the environment file at E:\react\jwt\src.env. in E:\react\jwt\src\vendor\vluca s\phpdotenv\src\Loader.php:107 Stack trace:

0 E:\react\jwt\src\vendor\vlucas\phpdotenv\src\Loader.php(84): Dotenv\Loader->e

nsureFileIsReadable()

1 E:\react\jwt\src\vendor\vlucas\phpdotenv\src\Dotenv.php(114): Dotenv\Loader->

load()

2 E:\react\jwt\src\vendor\vlucas\phpdotenv\src\Dotenv.php(52): Dotenv\Dotenv->l

oadData()

3 E:\react\jwt\src\bootstrap.php(6): Dotenv\Dotenv->load()

4 E:\react\jwt\src\generate_jwt.php(2): require('E:\react\jwt\sr...')

5 {main}

thrown in E:\react\jwt\src\vendor\vlucas\phpdotenv\src\Loader.php on line 107

Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read the environment file at E:\react\jwt\src.env. in E:\react\jwt\src\vendor\vlucas\php dotenv\src\Loader.php:107 Stack trace:

0 E:\react\jwt\src\vendor\vlucas\phpdotenv\src\Loader.php(84): Dotenv\Loader->e

nsureFileIsReadable()

1 E:\react\jwt\src\vendor\vlucas\phpdotenv\src\Dotenv.php(114): Dotenv\Loader->

load()

2 E:\react\jwt\src\vendor\vlucas\phpdotenv\src\Dotenv.php(52): Dotenv\Dotenv->l

oadData()

3 E:\react\jwt\src\bootstrap.php(6): Dotenv\Dotenv->load()

4 E:\react\jwt\src\generate_jwt.php(2): require('E:\react\jwt\sr...')

5 {main}

thrown in E:\react\jwt\src\vendor\vlucas\phpdotenv\src\Loader.php on line 107

asinduvg commented 4 years ago

I know this is late but I had the same issue and I simply named the file to ".env" NOT config.env, var.env e.t.c. From there now you just have to specify the path. I have the .env file at the root of my project and am using the Slim framework. As you know how this frameworks work/how directories are structured, people usually have a public sub-folder and an index.php file inside it which serves as the entry point to the application. If this is the case(mostly Laravel, Symfony e.t.c.) then you just need to get the location of .env file correctly e.g.

$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__ . '/../');

If it's in public, this suffices:

$dotenv = \Dotenv\Dotenv::createImmutable(__DIR__);

This worked for me. I previously had config.env and then I renamed it to .env and it worked. Thanks for the help.

samhk222 commented 3 years ago

After two hours struggling, in my case the problem was the .env file permission ... change it and you could solve it

jsbimra commented 3 years ago

If its too up ;) :D dig it up!

    require "../../vendor/autoload.php";
    $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . "./../../../");
    $dotenv->load();

    print_r($_ENV);

Then it works!

codingTheWorld777 commented 3 years ago

Hi, I have the same problem. When I launched my app (I have deployed it with Heroku), I receive the errors like: PHP Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/app/app/controller/.env]. in /app/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68 2021-06-13T23:38:59.855043+00:00 app[web.1]: Stack trace: 2021-06-13T23:38:59.855197+00:00 app[web.1]: #0 /app/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read() 2021-06-13T23:38:59.855344+00:00 app[web.1]: #1 /app/app/controller/config.php(12): Dotenv\Dotenv->load() 2021-06-13T23:38:59.855479+00:00 app[web.1]: #2 /app/app/controller/Controller.php(10): include('...') 2021-06-13T23:38:59.855585+00:00 app[web.1]: #3 /app/app/router/router2.php(116): Controller::accueil() 2021-06-13T23:38:59.855621+00:00 app[web.1]: #4 {main} 2021-06-13T23:38:59.855794+00:00 app[web.1]: thrown in /app/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68 Anyone can help me to find what is the main cause here?

kzths commented 3 years ago

If you are using 7.0 or higher, you may user dirname function and adjust the level (second parameter) to go up according to where the .env is stored.

e.g.

$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__, 2));

tastymousehub commented 3 years ago

I know this is late but I had the same issue and I simply named the file to ".env" NOT config.env, var.env e.t.c. From there now you just have to specify the path. I have the .env file at the root of my project and am using the Slim framework. As you know how this frameworks work/how directories are structured, people usually have a public sub-folder and an index.php file inside it which serves as the entry point to the application. If this is the case(mostly Laravel, Symfony e.t.c.) then you just need to get the location of .env file correctly e.g. $dotenv = \Dotenv\Dotenv::createImmutable(__DIR__ . '/../'); If it's in public, this suffices: $dotenv = \Dotenv\Dotenv::createImmutable(__DIR__);

This worked for me. I previously had config.env and then I renamed it to .env and it worked. Thanks for the help.

In my installation the file was called .env.example, so I removed the .example and the error was gone

luciojap commented 2 years ago

Solved with more accuracy in the project directory $dotenv = Dotenv\Dotenv::createImmutable(dirname(DIR, 1));

rahulsolankib commented 2 years ago

In my case, I removed the dot before env from this file vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php private const DEFAULT_NAME = '.env';

Raulbarossi commented 2 years ago

If u move your file from the folder where it was created symfony will keep looking for it on this folder, i've went on autoload_runtime and changed on $runtime variable where the project is, just worked for me, lets see on the last composer dump what just happens haha

salaahl commented 1 year ago

Hi, I have the same problem. When I launched my app (I have deployed it with Heroku), I receive the errors like: PHP Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/app/app/controller/.env]. in /app/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68 2021-06-13T23:38:59.855043+00:00 app[web.1]: Stack trace: 2021-06-13T23:38:59.855197+00:00 app[web.1]: #0 /app/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read() 2021-06-13T23:38:59.855344+00:00 app[web.1]: #1 /app/app/controller/config.php(12): Dotenv\Dotenv->load() 2021-06-13T23:38:59.855479+00:00 app[web.1]: #2 /app/app/controller/Controller.php(10): include('...') 2021-06-13T23:38:59.855585+00:00 app[web.1]: #3 /app/app/router/router2.php(116): Controller::accueil() 2021-06-13T23:38:59.855621+00:00 app[web.1]: #4 {main} 2021-06-13T23:38:59.855794+00:00 app[web.1]: thrown in /app/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68 Anyone can help me to find what is the main cause here?

Hello, did you manage to solve your problem? I have the same problem with Heroku...

Orange27-v commented 3 months ago

Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/Applications/XAMPP/xamppfiles/env]. in /Applications/XAMPP/xamppfiles/htdocs/vita/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/vita/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read() #1 /Applications/XAMPP/xamppfiles/htdocs/vita/env_setup.php(7): Dotenv\Dotenv->load() #2 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/vita/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68

I have same issue some please help me