I recently created a cache locking mechanism in our system to prevent race conditions. Most of the time, it works just fine (it creates a lock that is released after a certain period of time):
$lockedDriver = Cache::lock('book_driver_' . $driverData['id'], 15);
But sometimes, it causes errors like these:
Unable to create lockable file: /home/backridepal/public_html/storage/framework/cache/data/6a/44/6a441d0a993f4942895df68b5d5cb8d8e439a274. Please ensure you have permission to create files in this location. {"exception":"[object] (Exception(code: 0): Unable to create lockable file: /home/backridepal/public_html/storage/framework/cache/data/6a/44/6a441d0a993f4942895df68b5d5cb8d8e439a274. Please ensure you have permission to create files in this location. at /home/backridepal/public_html/vendor/laravel/framework/src/Illuminate/Filesystem/LockableFile.php:73)
file_put_contents(/home/backridepal/public_html/storage/framework/cache/datas/19/b8/19b8d39dc21197ef4f2f04faec3709e58764c278): failed to open stream: No such file or directory {"userId":7035,"exception":"[object] (ErrorException(code: 0): file_put_contents(/home/backridepal/public_html/storage/framework/cache/datas/19/b8/19b8d39dc21197ef4f2f04faec3709e58764c278): failed to open stream: No such file or directory at /home/backridepal/public_html/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:187)
So what I did was inspect my cache driver's path (I use file
value in config/cache.php
by the way). I executed ls -l storage/framework/cache/datas
in the terminal to check file permissions and found out that some files are owned by root
instead of backridepal
. I don't know what's causing other cache files to be owned by root
instead of backridepal
, I hope you can help me with this one.
Before I asked for help here, I already tried other solutions like running chown -R backridepal:backridepal storage/framework/cache
and running sudo chmod -R 775 storage
as root
user, but the errors I mentioned above still rarely occur.