Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjilliankramermcloughlin
3,428 PointsComposer autoload.php : No such file or directory, but the file and directory exists
I have installed composer on my OS X local computer. The composer.json file exists, and I was also able to successfully run composer require to install monolog. I see the vendor folder in my project root, and inside the vendor folder the autoload.php file exists with the following text:
// autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInite885cbf2a7e0a21593df67d4be077257::getLoader();
So far everything looks correct, until I create an index.php file and insert
require __DIR__ . '/vendor/autoload.php';
This throws the following error message:
Warning: require(autoload.php): failed to open stream: No such file or directory in - on line 2 Fatal error: require(): Failed opening required 'autoload.php' (include_path='.:') in - on line 2
I cannot figure out why this is happening because the relative path 'vendor/autoload.php' is correct, and the autoload file exists. I was able to solve the problem by using the full path of /Users/sjm/Dropbox/MAMP_htdocs/teamtreehouse/php/building_with_php/vendor/autoload.php. What am I doing wrong?
2 Answers
jilliankramermcloughlin
3,428 PointsYes, index.php is located in the base project directory which is building_with_php. Amazingly, I restarted my computer in a fit of frustration and that solved the problem. I guess the relative path must had been corrupted in memory in some may shape or form, because everything was a-ok when I restarted. I never would have guessed.... but I'm very glad the problem is solved!
Thanks for your help Simon.
Jon Edwards
7,913 PointsI know this question is old, but I had the same problem. I realized the index.php file must be located in the same folder as the composer.json file. This seems to solve the issue. I tried to create a project folder within this folder, but Composer seems to want to push everything up a directory.
Simon Coates
28,694 PointsSimon Coates
28,694 Pointsso index.php is in the base project directory. The only thing i can think of, is that if the autoload file is where it's meant to be, you're trying to access from outside the building_with_php directory, which would probably require altering the relative path. If it isn't this, I'm just as confused as you are.