The stream or file “/opt/lampp/htdocs/testproject/storage/logs/laravel-2021-08-31.log” could not be opened in append mode: failed to open stream: Permission denied
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
Problem
I’m getting this error after migrating my laravel project to linux server, see error below
UnexpectedValueException: The stream or file "/opt/lampp/htdocs/testproject/storage/logs/laravel-2021-08-31.log" could not be opened in append mode: failed to open stream: Permission denied in file /opt/lampp/htdocs/testproject/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php on line 110
Stack trace:
1. UnexpectedValueException->() /opt/lampp/htdocs/testproject/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:110
2. Monolog\Handler\StreamHandler->write() /opt/lampp/htdocs/testproject/vendor/monolog/monolog/src/Monolog/Handler/RotatingFileHandler.php:120
3. Monolog\Handler\RotatingFileHandler->write() /opt/lampp/htdocs/testproject/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php:39
4. Monolog\Handler\AbstractProcessingHandler->handle() /opt/lampp/htdocs/testproject/vendor/monolog/monolog/src/Monolog/Logger.php:344
5. Monolog\Logger->addRecord() /opt/lampp/htdocs/testproject/vendor/monolog/monolog/src/Monolog/Logger.php:712
6. Monolog\Logger->error() /opt/lampp/htdocs/testproject/vendor/laravel/framework/src/Illuminate/Log/Logger.php:176
7. Illuminate\Log\Logger->writeLog() /opt/lampp/htdocs/testproject/vendor/laravel/framework/src/Illuminate/Log/Logger.php:87
8. Illuminate\Log\Logger->error() /opt/lampp/htdocs/testproject/vendor/laravel/framework/src/Illuminate/Log/LogManager.php:500
9. Illuminate\Log\LogManager->error() /opt/lampp/htdocs/testproject/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:118
10. Illuminate\Foundation\Exceptions\Handler->report() /opt/lampp/htdocs/testproject/app/Exceptions/Handler.php:37
11. App\Exceptions\Handler->report() /opt/lampp/htdocs/testproject/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:92
12. Illuminate\Foundation\Bootstrap\HandleExceptions->handleException() [internal]:0
Solution
the error is that, Storage folder doesn’t have permission to write log files, you can run
chmod -R o+w projectname/storage
chmod -R o+w projectname/bootstrap
if you are using nginx then you need to use nginx user permission like below
sudo chown -R nginx:root storage
sudo chown -R nginx:root bootstrap
That’s All.
I hope this article helps you to solve the problem.
Thanks for reading.
Keep Exploring.