PHP - Dotenv not found?

Hi all,

I had this working earlier, andsorted out my folder structure. However, now I get this error: Uncaught Error: Class 'Symfony\Component\Dotenv\Dotenv' not found.

Here is my directory:

And here is my PHP:

require '../vendor/autoload.php';

use Symfony\Component\Dotenv\Dotenv;

$dotenv = new Dotenv();

// Constants. USE .ENV
$servername = getenv('SERVER');
$username = getenv('USER');
$password = getenv('PASS');
$dbname = getenv('DBNAME');

// Get values from form
$name=$_POST['name']; // set name from form to the variable 'name'
$location=$_POST['location']; // set location from form to the variable 'location'
$email=$_POST['email']; // set the email from the form to the variable form
$review=$_POST['review']; // review from form to variable form
$userinfo = date('Y-m-d H:i:s') . " - $_SERVER[REMOTE_ADDR]"; // collect info about the user

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
	die("Connection failed: " . $conn->connect_error);

$statement  = $conn->prepare("INSERT INTO reviewlist (name, location, review, userinfo, email, rating) VALUES(?,?,?,?,?,?)");
$statement->bind_param("ssssss", $name, $location, $review, $userinfo, $email, $rating);

if ($statement->execute() === TRUE) {
	echo "New record created successfully";
} else {
	echo "Error: " . $sql . "<br>" . $conn->error;


Anyone know why dotenv isn’t loading?

Thanks in advance!

Have you installed the dotenv component?

composer require symfony/dotenv

Yep, turns out it was because composer files need to be in home directory.