I got the following error when entering my site on a production server:
The stream or file "/var/app/current/storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied
I tried running the following commands and got Permisions denied in the terminal:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan optimize:clear
I ran chmod -R 775 storage/logs/
and composer dump-autoload
and I was able to get onto the home page of my site without any errors. After surfing around the site a bit more I was getting the same error in various areas and not in others:
Again same error
The stream or file "/var/app/current/storage/logs/laravel-2019-11-22.log" could not be opened: failed to open stream: Permission denied
I deleted the following files and ran php artisan cahce:clear
:
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
/bootstrap/cache/config.php.php
The only other advice I've seen is run:
sudo chmod -R 777 storage/*
Which seems like a bad idea on a production server, but seems to be upvoted answer. Should I just give my storage director 777 permissions and why? Is there another way of fixing this?
Edit:
I'm trying to do this as stated here:
// set current user as owner and the webserver user as the group
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
// set directory permission to be 775
chmod -R 775 storage
chmod -R 775 bootstrap/cache
but when I run sudo chown -R $USER:www-data storage
I get this error:
chown: invalid group: ‘myusername:www-data’
Alright I got the answer:
AWS AMI uses webapp
as the web user, not apache or ec2-user
as the file shows. In that case, the webapp
user has no access rights over those files.
sudo chown $USER:webapp ./storage -R
find ./storage -type d -exec chmod 775 {} \;
find ./storage -type f -exec chmod 664 {} \;
Using the console, go to your synced folder (vagrant)
sudo chown -R $USER:www-data storage
chmod -R 775 storage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With