Now and then we face a destructive issue within a Laravel project:
Storage log file
production.ERROR: Unable to create lockable file: /var/www/html/storage/framework/cache/data/... Please ensure you have permission to creto create files in this location.
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Filesystem/LockableFile.php(43)
When the issue happens ls -l
gives
drwxrwsr-x+ 2 apache apache 4096 Sep 2 14:36 logs
To solve the issue we run sudo chown -R ec2-user:apache logs/
which gives
drwxrwsr-x+ 2 ec2-user apache 4096 Sep 2 14:36 logs
But this is a manual fix…
Therefore, I would like to ask:
A) How to prevent the file system suddenly changing owner which breaks the coding?
B) Alternatively how to trigger production error notifications within a Laravel project to be warned about such issues?
2
Answers
Answer to your second query, you can use either of them for error reporting:
All the exceptions are handled by AppExceptionsHandler class and in this class, there is a method named register you can configure any of the above tools in there so that exceptions can be reported there. Else you can build your custom report method like sending an email to you with an exception message or sending a slack notification.
To fix this issue permanently you have to give the right permission in the code so go to
config/logging.php
you will find something like below:add
'permission' => 0775,
to the channels used, so it will be like below (I have added it tosingle
anddaily
channels):This fix Tested on Laravel 6