17

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

Pawan Rai
  • 401
  • 1
  • 3
  • 15
  • 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 Aug 01 '20 at 08:37
  • Checked from workspace container bash. storage/logs/ directory has `drwxr-xr-x 2 root root 4096 Aug 1 07:37 logs ` – Pawan Rai Aug 01 '20 at 09:02
  • Please see this as well: https://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 Aug 01 '20 at 10:46

6 Answers6

38

This worked for me:

chown -R www-data:www-data "project foldername"
Shayan Shafiq
  • 1
  • 5
  • 17
  • 24
MARIO MORENO
  • 481
  • 3
  • 3
  • when i paste this in my terminal in cpanel server it says "chown: invalid user: ‘www-data:www-data’" – ehsan asarzadeh Jul 21 '21 at 11:36
  • 1
    @ehsanasarzadeh it depens under which user your webserver is running. Sometimes it is apache, www-data, www or even root. find out which on is correct for you system an adapt the statement accordingly. – Calamity Jane Jul 23 '21 at 09:14
7

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!

Vivek Choudhary
  • 544
  • 7
  • 12
6

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
I B R A
  • 3
  • 1
Anjana Silva
  • 6,589
  • 4
  • 51
  • 49
5

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?

ChewySalmon
  • 471
  • 5
  • 20
3

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

step 1:

sudo chmod -R +rwX .

step 2:

sudo chown -R $(whoami) .

Najmul Hoq
  • 85
  • 1
  • 11
  • explain.. this didn't do anything to me.. – francisco Jan 15 '22 at 14:37
  • @francisco Thank you for your query. Basically, I was working on a laravel project in visual studio code and I got that storage issue. And then I open the visual studio code *terminal and executed those commands and it worked for me. – Najmul Hoq Jan 16 '22 at 14:33
3

Give group write access to /storage/logs/

sudo chmod g+w storage/logs
zEELz
  • 111
  • 6