laravel - The stream or file "/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied
My application is being deployed to AWS Lightsail(LAMP) and when I try to run artisan migrate it says:
```The stream or file "/opt/bitnami/projects/app-name/storage/logs/laravel.log" could not be opened in append mode: failed to o
pen stream: Permission denied```
What I have tried so far is to allow access to storage via:
```sudo chmod -R 775 storage```
but it is still giving me the error. What seems to be this issue?
Can you run ls -lah in the /opt/bitnami/projects/app-name/storage/ and /opt/bitnami/projects/app-name/storage/logs directories? There's a couple of things that could be happening here, but it depends on the permissions of the folder and the items in it.
ls is a Linux command that lists directory contents. ls -lah is saying list the directory specified, and specifying the options -lah which say that I want a different formatted output (l), I want to see all files even those starting with "." (a) and that I want output to be human readable (h).
I want to see what is in the directories and what the permissions are for the files and folders so that I can help you. As a side note, good for you for being wary of a random command given to you by someone on the internet (I didn't even think about how that might come across sketchy to someone new to Linux).
Ya, I was going to say, your storage folder probably has owner/group set to work with the web server, and your ssh user doesn't own the files or exist in the group.
Just so you know, sudo chmod -R ugo+rw storage is the same as sudo chmod -R 777 storage. 777 and ugo+rw both mean any logged in user can read, write, and execute a given file or folder. If this server is going to be used for a public application, I'd generally recommend you try to lock down your permissions a bit more. Not a requirement per-say, but it's good practice to be as restrictive as you can afford to be.
Happy you solved your issue! Since you're new to Linux, you should check out the man pages for chown and chmod which are directly related to the issue you were having.
@CookieMonster I have a problem , I have to run this command "sudo chmod -R ugo+rw storage" every day when a new log file is created and I don't know why. how can I fix this permanantly?
@mdoulabi Both commands aim to ensure that the user running the Laravel application (typically the web server, e.g. www-data) has write permissions to the storage folder so that the application can write log files and other data it needs. The first command (chmod -R 775) explicitly sets specific permissions, while the second command (chmod -R ugo+rw) simply adds read and write permissions for all user groups.
@jaderabbit Use chmod 777 its a very bad practice because everyone its gonna have permissions, if someone gain access to your server its gonna have the freedom of do whatever he wants with your project.