7
votes

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

6
What are the perms for the storage directory? It may be that the permissions for the directory are causing the issue here. You can find this with the ls -l /var/www/laravel-api/storage/ command in your terminal.ChewySalmon
Checked from workspace container bash. storage/logs/ directory has drwxr-xr-x 2 root root 4096 Aug 1 07:37 logs Pawan Rai
Please see this as well: vsupalov.com/docker-shared-permissions. The files that are created/overwritten by your docker containers in your shared folders can have undesirable permissions if you do not configure them correctly.Kurt Friars

6 Answers

26
votes

This worked for me:

chown -R www-data:www-data "project foldername"
3
votes

Give group write access to /storage/logs/

sudo chmod g+w storage/logs
3
votes

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?

2
votes

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

step 1:

sudo chmod -R +rwX .

step 2:

sudo chown -R $(whoami) .

1
votes

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
0
votes

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!