Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FIle could not be opened in append mode: failed to open stream: Permission denied laradock

I'm setting up laradock (Setup for Multiple Projects) following the official documentation from the Laradock in my local machine.

After installation I installed the laravel through workspace container bash. I did configured the config file for the app in nginx/sites/ directory and in /etc/hosts file.

While visiting the development url I'm getting the following error message:

The stream or file "/var/www/laravel-api/storage/logs/laravel.log" could not be opened in append mode: failed to open stream: Permission denied

like image 528
Pawan Rai Avatar asked Aug 01 '20 08:08

Pawan Rai


People also ask

Could not be opened in append mode failed to open stream Permission denied the?

Log" Could Not Be Opened In Append Mode: Failed To Open Stream: Permission Denied problem can be solved using the computer language. Another approach, which includes several samples of code, can be utilised to resolve the identical problem The Stream Or File /Storage/Logs/Laravel.

How do I give permission to storage in laravel?

Change all file permissions to 644. Change all folder permissions to 755. For storage and bootstrap cache (special folders used by laravel for creating and executing files, not available from outside) set permission to 777, for anything inside.


6 Answers

This worked for me:

chown -R www-data:www-data "project foldername"
like image 51
MARIO MORENO Avatar answered Oct 19 '22 08:10

MARIO MORENO


If you are still facing the issue even after changing the permission and owner of file, just check for the OS of you Linux server. Login to your server

$ ssh user@server-ip

check your OS running on linux server

$ cat /etc/os-release

//output

NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"

If it is CentOS, you need to disable Security-Enhanced Linux (SELinux) if enabled. Check for SELinux status

$ sestatus

If it is enabled, then

$ setenforce Permissive

Or

$ sudo setenforce 0

Have a good day!

like image 39
VPC Avatar answered Oct 19 '22 10:10

VPC


you have to enter the workspace first by typing "docker-compose exec workspace bash"(without quotes)

To give a write permission to a single file,

chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log

or

chmod -R 777 /var/www/laravel-api/storage/logs

or

sudo chmod -R 777 /var/www/laravel-api/storage/logs/laravel.log

when the same error appears but different folders or files, do the same thing only change the folder name

example :

chmod -R 777 /var/www/laravel-api/storage/logs

chmod -R 777 /var/www/laravel-api/storage/framework/views

chmod -R 777 /var/www/laravel-api/storage/framework/sessions
like image 33
Anjana Silva Avatar answered Oct 19 '22 08:10

Anjana Silva


If you aren't running your application as root on your web server, then it wont have write access based on the permissions you've provided.

Checked from workspace container bash. storage/logs/ directory has drwxr-xr-x 2 root root 4096 Aug 1 07:37 logs

The error is complaining about permission denial for opening in append mode - it doesn't have permission to write to the file, only root does.

What you need to do is make your web server group the owner of the storage directory:

chown -R www-data:www-data /var/www/laravel-api/storage/

The www-data can be switched out for whatever group your web server is associated with.

To avoid completely repeating an amazing and complete answer, I recommend you give this answer a read:

How to set up file permissions for Laravel?

like image 24
ChewySalmon Avatar answered Oct 19 '22 09:10

ChewySalmon


Give group write access to /storage/logs/

sudo chmod g+w storage/logs
like image 4
zEELz Avatar answered Oct 19 '22 10:10

zEELz


You need to run the following command. It works for me:

step 1:

sudo chmod -R +rwX .

step 2:

sudo chown -R $(whoami) .

like image 3
Najmul Hoq Avatar answered Oct 19 '22 08:10

Najmul Hoq