Laravel - Every new day I have this error : failed to open stream: Permission denied - laravel

i tried by giving permission (775) to bootstrap/cache and storage folder - it works fine on that day but next day it gives error again with new created log file.
The stream or file "/var/www/public_html/myProject/storage/logs/laravel-2021-03-31.log" could not be opened in append mode: failed to open stream: Permission denied in /var/www/public_html/myProject/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:111

i found the solution here:
i have two users on linux server
1 : ubuntu
2 : www-data
i added ubuntu user to www-data group and same as wwww-data to ubuntu group.
so now both users can read there files,
second thing i did is -> i updated app/config/logging.php
and define the permissions (0666) for newly created log file for "daily" and "single".

This might help you:
sudo chown -R www-data:www-data /var/www/{laravel_project_name}
link:
https://dev.to/613596/permission-denied-for-laravel-8-storage-logs-solved-2021-12ld

You have permission issue in your path /var/www/public_html/myProject/storage/logs/.
Try to run the following command
Change the files/directories group to apache/nginx, I used www-data it's the default user of apache on Ubuntu (Use your http server user/group name instead of www-data)
sudo chown :www-data -R /var/www/public_html/myProject/storage/
Now change the file permission once again
sudo chmod 775 -R /var/www/public_html/myProject/storage/
You can also add UID, GID, SID to handle more efficiently

Related

Error in laravel excel export - touch(): Unable to create file /var/folders/ because Permission denied

I install larvel excel and when i try to get the excel it shows the following error
touch(): Unable to create file /var/folders/wg/vbj_bbf14gl7glz__j1xpvg40000gn/T/laravel-excel-62n8RpljR3nr31FGxE96fwrovKEhXPWT because Permission denied
The excel is looking for a path to store the file temporarily before the data is imported. But the filepath leads to the system that maybe of Xampp or any other host that you are using which doesn't provide you the permission to write.
I solved this by going to excel.php file inside config folder and changing the path to
'local_path' => public_path('imported')
Hope this helps.
Add folders to server user-group and setup permissions to STORAGE + BOOTSTRAP/CACHE [on Apache - question did not state server arch]
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
sudo chgrp -R www-data /var/www/html/example/
sudo chmod -R 775 /var/www/html/example/storage

How can I make website with CRUDBooster and Laravel working?

Website based on CRUDBooster and Laravel not working
Tried to change permissions to main directory -r 777
(1/1) UnexpectedValueException The stream or file
"/var/www/storage/logs/laravel.log" could not be opened: failed to
open stream: Permission denied
I'm having this error when I'm trying to access website build with CRUDBooster and Laravel. Already tried to change permissions to 775 and 777 to all folders and subfolders inside but still same error.
Any idea?
Thank you in advance!
You need to give right permissions to storage and bootstrap/cache folders (sudo chmod -R 775 storage and sudo chmod -R 775 bootstrap/cache) and give right group permission to project folder (sudo chown -R $USER:www-data projectFolder). This last one (group permission) is for Apache server7

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 5.5: laravel.log could not be opened: Permission denied

I'm trying to run a simple Laravel command line on my Elastic Beanstalk instance: php artisan queue:work
But I keep getting the following error:
In StreamHandler.php line 107:
The stream or file "/var/app/current/storage/logs/laravel.log" could
not be opened: failed to open stream: Permission denied
I've tried every solution I can find on SO (except the chmod -R 777 advice that seems to trail this question everywhere).
I've tried deleting the existing laravel.log and then using touch to create a new one, and then making sure webapp is the owner.
I've also tried:
sudo chmod -R 755 /var/app/current/storage/
sudo chown -R webapp /var/app/current/storage/
When I list the logs directory, everything looks as I think it should:
-rwxr-xr-x 1 webapp webapp 0 Apr 4 14:38 laravel.log
The storage directory also looks fine:
drwxr-xr-x 6 webapp webapp 4096 Apr 3 19:33 storage
But I'm still getting the above error! Can anyone explain why (not just give a solution).
Thank you
So the simple answer is that I was running the command as ec2-user. As a solution, I could either:
Change the ownership of laravel.log to ec2-user
Run the command as the owner (eg. sudo -u webapp php artisan queue:work)
Switch to root with sudo su to see how it would be run during deployment (ie. as root)
Nothing was especially wrong.
When you log into an EBS instance via ssh, you're logged in as ec2-user.
I don't believe the ec2-user is part of the webapp group which is actually executing PHP & apache/nginx.
Try adding your ec2-user to the webapp group by creating an ebextension in the root of your Laravel project under .ebextensions/ec2user.config
users:
ec2-user:
groups:
- webapp
Prove this is the problem by turning off selinux with the command
sudo setenforce 0
This should allow writing, but you've turned off added security server-wide. That's bad. Turn SELinux back
sudo setenforce 1
Then finally use SELinux to allow writing of the file by using this command
sudo chcon -R -t httpd_sys_rw_content_t storage
And you're off!

PhpStorm - Deployment - Cannot Upload New Files

When I try to create a new file/folder in PhpStorm I get a Permission denied error. However, when I create a new file in a folder that already exists in the root directory of my server I can without any errors.
When I try to create a new file:
[2016-03-07 11:29 AM] Failed to transfer file 'C:\Users\D\PhpstormProjects\example2\test.php': could not write to "sftp://www.example.com/test.php". (Permission denied)
[2016-03-07 11:29 AM] Automatic upload completed in less than a minute: 2 items failed
When I try to create a new folder:
[2016-03-07 11:27 AM] Failed to create folder '/var/www/html/test': could not create folder "sftp://www.example.com/test". (Permission denied)
[2016-03-07 11:27 AM] Automatic upload completed in less than a minute: 1 item failed
You can try this :
chmod -R 777 /var/www
chgrp www-data /var/www
chown -R www-data /var/www
useradd -G {www-data} your_username
The issue solved itself after restart.
PhpStorm support gave this answer:
Please try to run File > Invalidate Caches/Restart > Invalidate and Restart.
If it still fails please send me idea.lof file as described here:
https://intellij-support.jetbrains.com/hc/en-us/articles/207241085-Locating-IDE-log-files
Prior to deleting, modifying and transferring files, you need to give them the permissions to the data group for the user who will perform the operations.
$ sudo usermod -a -G www-data your_username
$ sudo chgrp -R www-data /var/www/html
$ sudo chmod -R g+w /var/www/html
Checklist:
Make sure you own the files, so if you are in the sudo group then you can do sudo chown -R myusername:sudo /var/www/html/test/. This is to make sure that it will also work for other people in the group.
Make sure that you have write permissions, i.e. read and write access also for the group. You can do this with sudo chmod -R 755 /var/ww/html/test/ (Unfortunately I have found that in practice you sometimes need 777 permissions, but this is not desirable.)
Make sure your deployment path mappings are correct, by going to Settings | Deployment | Mappings, and check that the Deployment path is indeed relative to the root path (under Connection)
After fixing permissions on server you need restart phpstorm. Worked for me on Ubuntu 17.10

Resources