Wrong permissions (Group/user) for the occasional cache file in Laravel - laravel

I've set all the permissions up and everything has been working perfectly for about 2 years until today when I force cleared the cache using php artisan cache:clear
Now, when the cache gets created in /storage/framework/cache, it works fine and all the permissions are set correctly except for the occasional file.
I could have thousands of cache files in there, all with the correct permissions (www-data as user and group). . but then randomly one file will generate using the wrong permissions which ends up with this error.
file_put_contents(/.../.../storage/framework/cache/data/52/cf/52cf02760233b9fc625602f52fd0748a51ac772a): failed to open stream: Permission denied
When I navigate to the file, the permissions are set to 744 and the user/group is set to root:root. Every other cache file is set to 774 and www-data:www-data.
I can fix it temporarily by running sudo chown -R www-data:www-data storage which sets the folders to the correct group and user but then the error appears again after about 15 minute once another file generates with the incorrect permissions.
What can be causing this?

Related

Laravel Cache files losing permissions - Windows 10 IIS & Active Directory

My problem is that when I use caching in Laravel with file driver, I occassionally lose permissions to the cache file. Permissions are set properly, parent folder does not lose any permissions, only the specific cache file. After restarting the machine, permissions are back and I can delete the file manually.
The "permission" error is like:
file_put_contents(C:\inetpub\wwwroot\office_map_dev\storage\framework/cache/data/ca/0d/ca0d727b27eefcb8763203d9ad28f5a5eb29a85e): Failed to open stream: Permission denied

How to solve the problem of accessing the storage in Laravel folder

Faced a problem accessing the storage folder. A symbolic link was created, but when I try to access any file in the storage folder, I get an error 403 "You do not have permission to access this object. The file is not readable, or the server cannot read it." I have a second project on a local machine, everything works fine there. I tried to give 777 permissions to the storage folder, but this causes the "Permisson denied" error. I will be glad to any help!
Macos catalina
Laravel Permissions
first change ownership of the laravel directory to our web group.
sudo chown -R :www-data /var/www/laravel
Next we need to give the web group write privileges over our storage directory so it can write to this folder.
sudo chmod -R 775 /var/www/laravel/storage
where laravel is the name of the root

Permission denied in logs from time to time

From time to time, everytime I want to clear cache or something related I got this error:
Uncaught UnexpectedValueException: The stream or file "laravel_system/storage/logs/laravel-2019-01-28.log" could not be opened: failed to open stream: Permission denied in /laravel_system/bootstrap/cache/compiled.php:13761
The entire Log folder has www-data:www-data and 777 permissions, but when this happens there are some log files that are either with ubuntu or www-data or don't have 777 permissions.
It's not really a big problem, I just change permissions for the folder again and config:cache works again...but I wonder what I'm missing here since it happens every now and then.

Laravel 5.3 Cannot Find File Error

I've setup a project more than a month ago and all of a sudden (this afternoon) I started getting the following error:
ErrorException in Filesystem.php line 111: file_put_contents(/var/www/html/project/api/storage/framework/cache/d8/00/d800874b5dc22b961e0ee92f8d1c5a09c24ee911): failed to open stream: No such file or directory
I've done research and tried the following with no success:
php artisan cache:clear
chmod -R 777 storage (I know this is not ideal)
composer update
Nothing is working. Before the chmod I was getting a permission error. I'm tapped out of ideas. Does anyone know what is causing this and how to resolve it?
You gave 777 to /storage folder but did you also make sure it's in same group as apache server is running?
Generally apache is in www-data group, add storage and bootstrap folder to be written by this group:
chgrp -R www-data /storage /bootstrap
Assign current user and group permission to read and write:
chmod -R ug+rw /storage /bootstrap
I'm 99% sure this will do it.
My server runs CentOS 7 and somehow Selinux was set to enforcing which breaks Laravel for some reason. I remember changing it when I first set up Laravel, but somehow it reverted back.
So setting it to permissive or disabled fixed it for me.
https://www.centos.org/docs/5/html/5.2/Deployment_Guide/sec-sel-enable-disable.html

Hosting with OpenShift RedHat get 500 errors when access the website

I have this website. The problem I have is
The freelancer-ngohungphuc.rhcloud.com page isn’t working
freelancer-ngohungphuc.rhcloud.com is currently unable to handle this
request.
500
I develop this website using Laravel 5.1. So what I have to do to fix this error.
Although you can usually check logs to see why you are getting a 500 error, it would appear that this is due to insufficient permissions - which need to be set on the storage and bootstrap/cache folders (as per the docs).
The folders both need to be writeable by your web server, so whilst 777 permissions will definitely work 775 should be fine (and more secure).
Doing this via a command line can be done with the following command (run it with sudo if you need to elevate to root permissions) chomd 777 -R storage bootstrap/cache or chomd 775 -R storage bootstrap/cache.
Doing this via an FTP client is doable, generally speaking you can just right click on the folder and choosing to edit permissions from there.
In some instances, vendor may need to be done too - from my experiences anyway.
These folders are all inside the root project directory for your Laravel application.
Edit
Excerpt from bottom of error log:
PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE)
This would indicate that the PHP version you are running is not >= 5.5.9 (one of the Laravel requirements).
This is confirmed in the screenshot shown of the OpenShift configuration. The version of PHP needs to be updated for Laravel to work - this wasn't just a permission issue.

Resources