Search code examples
linuxamazon-ec2laravel-5file-permissions777

Laravel fails to write to /storage with permission 775 - Amazon AWS Linux


I am trying to get my Laravel 5.3 installation to work on a Amazon Linux AMI EC2 instance.

So far everything is set up:

  • apache, php, etc.. ok
  • laravel set up in www/html/blog

folder permissions were set to 775 (following the AWS docs):

drwxrwsr-x  6 ec2-user www   4096 Sep 20 13:38 app
-rwxr-xr-x  1 ec2-user www   1646 Sep 20 13:38 artisan
drwxrwsr-x  3 ec2-user www   4096 Sep 20 13:38 bootstrap
-rw-rw-r--  1 ec2-user www   1283 Sep 20 13:38 composer.json
-rw-rw-r--  1 ec2-user www 124068 Sep 22 17:27 composer.lock
drwxrwsr-x  2 ec2-user www   4096 Sep 20 13:38 config
drwxrwsr-x  5 ec2-user www   4096 Sep 20 13:38 database
-rw-rw-r--  1 ec2-user www    556 Sep 20 13:38 gulpfile.js
-rw-rw-r--  1 ec2-user www    400 Sep 20 13:38 package.json
-rw-rw-r--  1 ec2-user www    930 Sep 20 13:38 phpunit.xml
drwxrwsr-x  4 ec2-user www   4096 Sep 20 13:38 public
-rw-rw-r--  1 ec2-user www   1918 Sep 20 13:38 readme.md
drwxrwsr-x  5 ec2-user www   4096 Sep 20 13:38 resources
drwxrwsr-x  2 ec2-user www   4096 Sep 20 13:38 routes
-rw-rw-r--  1 ec2-user www    563 Sep 20 13:38 server.php
drwxrwsr-x  5 ec2-user www   4096 Sep 20 13:38 storage
drwxrwsr-x  2 ec2-user www   4096 Sep 20 13:38 tests
drwxrwsr-x 31 ec2-user www   4096 Sep 22 17:27 vendor

Now if I set permission 777 on /blog/storage, Laravel loads just fine, but I am not sure if this is a good idea.

Why the Apache2 server can't write to /blog/storage with permission 775, while the owner group is www ? Thanks!


Solution

  • With 755 permission, owner which is ec2-user in your case will have write permission whereas the group www will have read and execute permission only to that directory.

    You can use acl to grant write permissions for user who is running the process instead of granting 777

    setfacl -m u:user:rwx /blog/storage