Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GodziLaravel's avatar

Is there a way to fix the 'failed to open stream: Permission denied' ?

Hello I have in several times the error related to:

Error in exception handler: The stream or file "/var/www/laravel/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

To fix this (manually) I need always to run those commands bellow:

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

Here how looks the permissions of my files:

drwxrwxr-x   5 davy www-data     70 Nov 30 10:44 storage/
storage/
total 12
drwxrwxr-x  5 davy www-data   70 Nov 30 10:44 ./
drwxrwsrwx 17 ubuntu      www-data 4096 Jan 20 10:25 ../
drwxrwxr-x  5 davy www-data   72 Jun  8  2022 app/
-rwxrwxr-x  1 davy www-data 2355 Sep  2  2021 credentials.json*
drwxrwxr-x  6 davy www-data   81 Sep 23  2021 framework/
drwxrwxr-x  2 davy www-data 4096 Jan 20 10:23 logs/
storage/logs/
-rwxrwxr-x 1 davy www-data      7665 Jan 16 00:00 laravel-2023-01-16.log*
-rwxrwxr-x 1 davy www-data    118676 Jan 17 05:31 laravel-2023-01-17.log*
-rwxrwxr-x 1 davy www-data     19299 Jan 18 15:51 laravel-2023-01-18.log*
-rwxrwxr-x 1 davy www-data      7665 Jan 19 00:00 laravel-2023-01-19.log*
-rwxrwxr-x 1 davy www-data      7665 Jan 20 00:00 laravel-2023-01-20.log*

any idea ? thanks

0 likes
3 replies
s4muel's avatar

do you have any other process writing that file (or creating the folder)? e.g. cron, or deploy script that is not in www-data group?

i noticed laravel.log in the error message, but in the directory contents, you have 'daily' log files laravel-2023-01-16.log. this should be no problem, but seems like different configuration for what writes to your log.

s4muel's avatar

@GodziLaravel then make sure the cron job is running under a user that is in www-data group

either in a crontab of such user or if using a common crontab (on linux e.g. /etc/crontab or a file in /etc/cron.d/) there is a (6th) column where to put a username

1 1 * * * username /path/to/your/script.sh

Please or to participate in this conversation.