0

PHP is throwing this error when trying to access autoload: require_once __DIR__ . '/../vendor/autoload.php';

Warning: require_once(/Applications/MAMP/htdocs/crud_app/public/vendor/autoload.php): Failed to open stream: No such file or directory in /Applications/MAMP/htdocs/crud_app/public/index.php on line 6

The thing is that if I echo __DIR__.'/../vendor/autoload.php'; it shows /Applications/MAMP/htdocs/crud_app/public and the vendor directory is outside of public. This is the path where autoload.php is:

/Applications/MAMP/htdocs/crud_app/controllers/vendor/autoload.php

Any idea what is happening? This is my repo in case you want to look at it. Running PHP 8.1 and macOS. Thanks in advance.

Labanino
  • 3,902
  • 9
  • 33
  • 51
  • 1
    Does this answer to your question ? https://stackoverflow.com/questions/5116421/require-once-failed-to-open-stream-no-such-file-or-directory – debugger Sep 08 '22 at 15:58

1 Answers1

2

index.php isn't inside controllers, you need to add that to the path.

require_once __DIR__ . '/../controllers/vendor/autoload.php';
Barmar
  • 741,623
  • 53
  • 500
  • 612