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 trialJaymes Young
36,282 PointsFatal Error Using namespaces in PHP - Build A Simple Website
This is there error I am getting
Fatal error: Uncaught UnexpectedValueException: The stream or file "app.txt" could not be opened: failed to open stream: Permission denied in /home/treehouse/workspace/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:97 Stack trace: #0 /home/treehouse/workspace/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array) #1 /home/treehouse/workspace/vendor/monolog/monolog/src/Monolog/Logger.php(336): Monolog\Handler\AbstractProcessingHandler->handle(Array) #2 /home/treehouse/workspace/vendor/monolog/monolog/src/Monolog/Logger.php(391): Monolog\Logger->addRecord(300, 'Foo', Array) #3 /home/treehouse/workspace/index.php(8): Monolog\Logger->addWarning('Foo') #4 {main} thrown in /home/treehouse/workspace/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 97
This question has been asked twice previously with no replies.
4 Answers
Cindy Lea
Courses Plus Student 6,497 PointsIt would be better to show the code you are using. If its a Treehouse assignment, attach challenge too.
Jaymes Young
36,282 PointsI found my own solution. Simply delete the app.txt file and it seems to work again. A new app.txt file will be created when you run the program again.
Ryan Moody
20,499 PointsWarning: require(vendor/autoload.php): failed to open stream: No such file or directory in /home/treehouse/workspace/vendor/index.php on line 2
Fatal error: require(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/treehouse/workspace/vendor/index.php on line 2
This is what I am getting too. Please help.
henrihouthoff
33,595 PointsThe reason why this happens is because of Linux user permissions. When the file is created at first as in the previous video, the owner of the file (with read and write permissions) is user "treehouse". When using 'use' the executing script is apparently owned by user 'apache' and only has read access to the file. You can either change file permissions or delete the file and recreate it with the new setup.
Jaymes Young
36,282 PointsJaymes Young
36,282 PointsThis is the code I am using <?php require DIR . '/vendor/autoload.php'; date_default_timezone_set('America/Los_Angeles');
$log = new Monolog\Logger('name'); $log->pushHandler(new Monolog\Handler\StreamHandler('app.txt', Monolog\Logger::WARNING));
$log->addWarning('Foo'); echo 'Hello World!';
It worked when I created it, once I added namespaces using 'USE' it stopped working. When I reverted back to the original code 'shown above' I got the same error.