15

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?

Md Hasibur Rahaman
  • 1,041
  • 3
  • 11
  • 34
  • Possible duplicate of [file\_put\_contents permission denied](https://stackoverflow.com/questions/4917811/file-put-contents-permission-denied) – Tobias F. Sep 05 '18 at 06:08

7 Answers7

58

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)

Shobi
  • 10,374
  • 6
  • 46
  • 82
7

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

vuhung3990
  • 6,353
  • 1
  • 45
  • 44
5

On Centos or Red Hat

Do this first

 # sestatus

if the status is enabled, you have to disable it

# setenforce Permissive

for me the group and user is nginx so

chown -R nginx:nginx storage bootstrap/cache
chmod -R 775 storage
chmod -R 775 bootstrap/cache
3

try changing the owner of the folder and change the permission of folders

sudo chown -R www-data storage/logs/
sudo chmod g+w -R storage/logs

now apply all the rules for child files folder logs

cd storage/logs
sudo find . -type d -exec chmod g+s '{}' +
Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
bakha
  • 311
  • 2
  • 8
2

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.

Javad.mrz
  • 207
  • 2
  • 5
1

This should help you

chcon -R -t httpd_sys_content_t $SITE_PATH

chcon -R -t httpd_sys_rw_content_t $SITE_PATH

Sachin
  • 33
  • 3
0

The shortest way I found to fix it:

php artisan storage:link
sudo chown -R $USER:www-data storage bootstrap/cache
DevonDahon
  • 7,460
  • 6
  • 69
  • 114