Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The stream or file "laravel.log" could not be opened: failed to open stream: Permission denied"

I upload the file to my cent OS server a few days ago, it was working fine, but from today I am getting the error.

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

Where My log file is with 777 permission I am also trying with 0755, 0644

can anyone tell me how I can resolve this issue?

like image 600
Md Hasibur Rahaman Avatar asked Sep 05 '18 05:09

Md Hasibur Rahaman


3 Answers

first try this to take ownership of the directory recursively

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

Then use the following to set proper directory access

chmod -R 775 storage
chmod -R 775 bootstrap/cache

Never Set dircetory permissions to 777 (Unless you know what you are doing)

like image 65
Shobi Avatar answered Oct 26 '22 18:10

Shobi


Note that you must change both. the ownership and permission, as well as the folders in these two folders. This should affect to all children

sudo chown -R apache storage
sudo chown -R apache bootstrap/cache

and

chmod -R 775 storage
chmod -R 775 bootstrap/cache

you can check owner

ls -lr 

That command will show you who has ownership.

like image 38
Javad.mrz Avatar answered Oct 26 '22 18:10

Javad.mrz


check current user: <?php echo exec('whoami'); ?> i'm using lampp on ubuntu, so the result is daemon

then run several command, thank @Shobi

sudo chown -R daemon:www-data storage
sudo chown -R daemon:www-data bootstrap/cache

now it works

like image 37
vuhung3990 Avatar answered Oct 26 '22 20:10

vuhung3990