0

I am looking for a more detailed answer from the following resolved issue "The stream or file "laravel.log" could not be opened: failed to open stream: Permission denied"

I am still new to web development and when entering the suggested command (sudo chown -R $USER:www-data storage) in the terminal I get the following error: chown: invalid group: ‘root:www-data’

I have also tried (sudo chown -R www-data:www-data /home/EXAMPLE/EXAMPLE) leading to my project folder but got the following error: chown: invalid user: ‘www-data:www-data’

I am doing this to fix a permissions issue:

The stream or file "/home/EXAMPLEURL/EXAMPLEURL/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied.

I have found the user and group is 'nobody' by using the following commands (find / -name httpd.conf | xargs grep -i "^user") and (find / -name httpd.conf | xargs grep -i "^group").

In the terminal I have tried the following command (sudo chown -R nobody:nobody /home/EXAMPLE/EXAMPLE/storage) in the storage folder, the level above it and the level above that. The terminal returns no error but the permissions error still shows on the live website

Thank you!

3 Answers3

1

Run this below command in your server/terminal

chmod -R 775 storage

It changes read/write permission for the storage folder.

  • I entered the command (chmod -R 775 storage) which returned a no directory error. I then replaced storage with /home/EXAMPLE/EXAMPLE which returned no error but made no change. I then also tried /home/EXAMPLE/EXAMPLE/storage/logs which again returned no error but no change. – Strawberry_cat_guy Oct 12 '21 at 06:09
  • You have to be in exact storage path to run that command. For eg- if the storage path is - var/www/vhosts/example.com/httpdocs/storage, then you have to run that command on this path - var/www/vhosts/example.com/httpdocs – Deepak Kotian Oct 12 '21 at 06:17
  • Thank you for the further help! So I went directly to the storage path (/home/EXAMPLE/EXAMPLE) and ran the command (chmod -R 775 /home/EXAMPLE/EXAMPLE/). This made no changes so I went one level above and tried the same command as well as (chmod -R 775 /home/EXAMPLE/). Still no changes. – Strawberry_cat_guy Oct 12 '21 at 06:24
  • Try to run this command before running that above command chown -R username:psacln storage - in the above "username" is your server login username – Deepak Kotian Oct 12 '21 at 06:31
  • Error: chown: invalid group: ‘USERNAME:psacln’ – Strawberry_cat_guy Oct 12 '21 at 06:36
  • Check your groups in root, then run that command. – Deepak Kotian Oct 12 '21 at 06:40
  • First command (groups root) returned: root : root Second command (chown -R root:root /home/EXAMPLE/EXAMPLE) returned no error. Third command (sudo chown -R www-data:www-data /home/EXAMPLE/EXAMPLE) returned: chown: invalid user: ‘www-data:www-data’ – Strawberry_cat_guy Oct 12 '21 at 06:50
0

Unlike Debian/Ubuntu, CentOS doesn't use www-data.

I'm pretty sure that the user and group is apache in your case. So, something like the following should do the trick:

sudo chown -R apache:apache /home/EXAMPLEURL/EXAMPLEURL/storage
Rwd
  • 34,180
  • 6
  • 64
  • 78
  • I have found the user and group is 'nobody' by using the following commands (find / -name httpd.conf | xargs grep -i "^user") and (find / -name httpd.conf | xargs grep -i "^group"). I have tried the command you suggested while in the storage directory and the level above it (sudo chown -R nobody:nobody /home/EXAMPLE/EXAMPLE/storage). No errors but still the same permission denied error – Strawberry_cat_guy Oct 13 '21 at 04:37
0

Solution, courtesy of a kind soul named Rashedul.

The reason the above solutions didn't work was that previously the owner was nobody. Changing the owner to root allowed the change to take effect

sudo chgrp -R $USER Storage_path