Permission denied in logs from time to time - laravel

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.

Related

Wrong permissions (Group/user) for the occasional cache file in 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?

xampp ubuntu laravel The stream or file "/storage/logs/laravel log" could not be opened: failed to open stream: Permission denied

installed laravel on my xampp installation on ubuntu. opened it in browser. got the error:
The stream or file /storage/logs/laravel log could not be opened: failed to open stream: Permission denied
how to fix? (i've already found an answer, will post right now)
the problem is that the user under which the apache runs doesn't have access to the folder. in xampp on ubuntu, the user of main apache process is root. but apache workers run under daemon user. the solution is to grant daemon access to the /storage dir. (if you'll only grant to /storage/logs than you'll fix this error, but the same error will occur with sibling dirs. thus the storage itself folder:
sudo chown -R daemon /path-to-your-project/storage
now the daemon user has access to this folder (and you don't but do you need it?
if you have better solutions, please feel free to share them here!
Add to composer.json
"scripts": {
"post-install-cmd": [
"chgrp -R www-data storage bootstrap/cache",
"chmod -R ug+rwx storage bootstrap/cache"
]
}
Then run composer install or update solve your issue

Laravel - The stream or file failed to open stream: Permission denied

I know this is a common problem on Laravel, but I think I'm having a different issue or else the settings aren't being updated.
I've looked at this Laravel The stream or file "/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied and this How to set up File Permissions for Laravel 5 (and others) but I still have this issue:
The stream or file "/var/www/html/laravelwebapp/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
When I do this after going into the logs directory: $ ls -l laravel.log
I get this:
-rwxrwxr-x 1 apache apache 0 Feb 8 2018 laravel.log
I'm on CentOS which is why the group/user is apache not www-data. Yet even though the log is created by apache and apache is the owner and group, it can't open the stream? Does this mean Laravel is executing as another user? I'm a bit confused here, sorry :/
I've cleared the cache using artisan and also ran composer dump-autload but I can't seem to progress in my application because the log doesn't get written to.
Update: My php application is running as nobody when I run
echo exec('whoami');
Is this the problem and how do I fix that?

Laravel New Project - Permission Denied

I am trying to setup a new Laravel site and I am running into an issue I have never had such problems with before. When loading up my site, I get the error:
The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
I have edited the file permissions to 775. I don't know what else to do!
Try changing the owner of the folder:
chown -R apache:apache /var/www/html/
you should change your project folder permission
The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
This error basically happens when in your project absent ../storage/logs folder. Firstly you must be check this folder exists in your project. If does not exist this folder add it and inside it .gitignore file.
/storage/logs/.gitignore
*
!.gitignore

When I upload my CodeIgniter System to my Amazon EC2, why are all of my permissions messed up?

For some weird reason, my "system" folder has permissions of "000" when I upload it. This totally breaks CodeIgniter as I get all sorts of errors:
Message: CI_Config::include(/[mysite]/system/application/config/assetlibpro.php) [ci-config.include]: failed to open stream: Permission denied
I don't think this is an EC2-specific problem. If you fix the permissions using
chmod -R 755 /[mysite]/system
you should be OK (755 means read/write/execute for owner, read/execute for group and world)

Resources