1

Well I'm stumped. I've been trying to work this out for several hours, plenty of Googles later and nothing. /rant.

I'm new to Auth0 and figured I'd give it a go but I'm getting the error below. I'm using their PHP sample project which you can find here: https://github.com/auth0-samples/auth0-php-web-app/tree/master/00-Starter-Seed/basic-webapp

I've installed composer and installed the dependencies. I've renamed ensured that I have .env setup correctly. I'm running this in XAMPP.

Fatal error: Uncaught Error: Class 'Dotenv\Dotenv' not found in /Users/.../htdocs/oa/dotenv-loader.php:6

I've tried different varations of the dotenv-loader.php show below but with no luck. Does anyone have any advice?

try {
  $dotenv = new Dotenv\Dotenv(__DIR__);
  $dotenv->load();
} catch(InvalidArgumentException $ex) {
  // Ignore if no dotenv
}

  // Read .env
  $dotenv = new Dotenv\Dotenv('.env');
  if(file_exists(".env")) {
      $dotenv->load();
  }

  $dotenv = new Dotenv\Dotenv(__DIR__);
//Check if file exists the same way as dotenv does it
//See classes DotEnv\DotEnv and DotEnv\Loader
//$filePath = $dotenv->getFilePath(__DIR__);
//This method is protected so extract code from method (see below)

$filePath = rtrim(__DIR__, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR . '.env';
if(is_file($filePath) && is_readable($filePath)) {
    $dotenv->load();
}

Thanks a lot in advance.

James
  • 474
  • 4
  • 9
  • 22
  • Class not found. Are you using autoload, require/include or what to load this class into your file? – Felippe Duarte Nov 18 '16 at 19:32
  • 1
    Hey thanks fro reply. Yeah within the index.php I'm calling the "require 'autoload.php'". Was there somewhere else you were thinking it should go? – James Nov 18 '16 at 19:36
  • 1
    In my case (2022-08): I encountered the "PHP Fatal error: Uncaught Error: Class "Dotenv\Dotenv" not found ..." The issue, described at https://dev.to/eriesgo/dotenv-and-relative-paths-fp2 , was to edit the path in the file:line indicated in the error. In my case, in `.dotenv.php` I needed to change the relative path `require_once('vendor/autoload.php');` to the full path (obfuscated here) `require_once('/home/me/.../vendor/autoload.php');` – Victoria Stuart Aug 05 '22 at 21:10

1 Answers1

1

Upon reading Google's login API, I realised you need to run 'composer install' where ever you composer.json is located, this seems to have fixed the issue. I'll update this should this not be the case.

James
  • 474
  • 4
  • 9
  • 22