Laravel The stream or file "storage/laravel.log" could not be opened in append mode: failed to open stream: Permission denied in RHEL8
Asked Answered
E

7

11

I need help here. I installed Laravel in my RHEL 8 Server

But I'm getting this error. I know this question already posted many times but I tried to follow the suggestion but no luck for me so far. I have no idea why.

The stream or file "/var/www/html/vpa/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied

enter image description here I tried to use this command to change the permission but it didn't work .

sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache 
sudo chmod -R 755 storage
sudo chmod -R 755 bootstrap/cache

sudo setenforce 0 
sudo chcon -t httpd_sys_rw_content_t storage

php artisan config:clear
php artisan config:cache
composer dump-autoload

sudo systemctl restart httpd
sudo reboot 

Nothing seems to work on my side . I don't know what else to do. Please help me

Engels answered 27/10, 2020 at 9:8 Comment(4)
I'm also facing this issue. I'm running my app on Nginx though. Anyway it's been some time. Have you been able to solve it on your own eventually?Puss
I just managed to resolve my issue by running setenforce 0.Puss
@KelvinLow. I found the solution in RHEL8 . You need to set chmod to 775 to folder storage and bootstrap/cache instead of 755. And yes , you need to 'setenforce 0'Engels
Good to know. Do you mind answering your own question so that other people will know that your question has been answered?Puss
S
17

on ubuntu this step solved it

php artisan config:clear

php artisan cache:clear

sudo chmod -R 775 /var/www/your_folder

sudo chown -R www-data:www-data var/www/your_folder 
Subvene answered 9/3, 2021 at 9:8 Comment(0)
M
2

Never use 777, the appropriate permissions is it:

if debian based

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chgrp -R www-data ./storage ./bootstrap/cache
chmod -R ug+rwx ./storage ./bootstrap/cache

if RHEL based

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chgrp -R apache ./storage ./bootstrap/cache
chmod -R ug+rwx ./storage ./bootstrap/cache

The important thing here is that the temporary directories are owned by the group that controls Apache.

You must be careful when handling permissions, because there are certain applications of the operating system that if they become vulnerable could access another user's script, so a 777 permission will allow writing it from another user and executing it from another user, which is a security risk.

You must be strict that only the user in question can manage it and, if necessary, the group to which it belongs. It is also recommended that the user have the Apache group assigned. Example:

adduser -aG apache $USER

https://gist.github.com/NeftaliYagua/825b6ce483b92a296caa0f37e4ff040a

Update 18 March 2024

Merrilee answered 18/3, 2021 at 5:34 Comment(0)
P
1

In my case, apart from ensuring all permissions were correct, I also had to disable SELinux.

Puss answered 10/12, 2020 at 17:17 Comment(0)
T
1

I had changed my storage permission by run following command.It works for me:

step 1:

sudo chmod -R +rwX .

step 2:

sudo chown -R $(whoami) .

Tobar answered 13/12, 2020 at 5:38 Comment(2)
Could you please add where you are? What is the path where you're executing those commands.Gynaecocracy
@Gynaecocracy Thank you for your query. Basically, I was working on a laravel project in visual studio code and I got that storage issue. And then I open the visual studio code *terminal and executed those commands and it worked for me.Tobar
A
1

this work for me

sudo chown -R www-data:www-data ./storage
find ./storage -type d -exec chmod 775 {} \;
find ./storage -type f -exec chmod 664 {} \;
sudo chown www-data:www-data ./bootstrap/cache -R
find ./bootstrap/cache -type d -exec chmod 775 {} \;
sudo chown -R www-data:www-data .env
find .env -type d -exec chmod 775 {} \;
Alesandrini answered 13/2, 2021 at 3:6 Comment(0)
J
0

Simply Read/Write Permission Allow run this commnad

chmod -R 755 /storage/laravel.log”
Jun answered 27/1, 2021 at 12:5 Comment(1)
Never recommend 777. 755 is far better.Gynaecocracy
R
0

Worked for me.

sudo chown -R $USER:$USER /var/www
sudo chmod -R 755 /var/www
sudo chmod -R 755 storage/*
sudo chmod -R 755 bootstrap/*
Radicalism answered 6/2, 2021 at 7:42 Comment(1)
Never recommend 777. 755 is far better.Gynaecocracy

© 2022 - 2024 — McMap. All rights reserved.