0

I'm having a problem setting up phpdotenv in my PHP project.

Notice: Undefined index: APP_NAME in /media/undefined/work/Php/miniframework/bootstrap/app.php on line 17

My folder structure

miniframework

  • app
  • bootstrap
    • app.php
  • public
    • index.php
  • vendor
  • .env
  • composer.json

The code is from bootstrap/app.php file.

<?php


session_start();


require_once __DIR__ . '/../vendor/autoload.php';


use Dotenv\Dotenv;


$dotenv = Dotenv::createImmutable(__DIR__, '/..//')->load();


var_dump($_SERVER['APP_NAME']); 
Ittisafur
  • 23
  • 4
  • From the package's [github page](https://github.com/vlucas/phpdotenv) for `createImmutable`: "_Optionally you can pass in a filename as the second parameter, if you would like to use something other than .env_" You pass `'/..//',` is that the file you want to load? – brombeer Aug 25 '20 at 07:02
  • My `.env` file not in the bootstrap/app.php it's in the root folder which is miniframework. If I don't pass anything as the second parameter it throws an error bootstrap/.env is not found. – Ittisafur Aug 25 '20 at 07:06
  • The path can be set in the _first_ parameter, as said, the second parameter is the filename. Maybe try `Dotenv::createImmutable(__DIR__ . '../')->load()`. – brombeer Aug 25 '20 at 07:09

0 Answers0