hieuhtr / Blog

Don’t be lazy. Don’t make excuses. No one cares. Work fucking harder.
Other
6 stars 2 forks source link

File permission in Symfony #66

Open hieuhtr opened 7 years ago

hieuhtr commented 7 years ago

Problem:

Stack: Nginx - PHP7-FPM - Symfony Nginx error log:

Runtime Exception : Unable to create the cache directory (var/app/cache/dev). ... 

Root cause & solutions:

Root cause: One important Symfony requirement is that the var directory must be writable both by the web server and the command line user.

Solutions:

  1. Install acl and grant the needed permissions
    $ sudo apt-get update
    $ sudo apt-get install acl
    $ HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\  -f1)
    $ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
    $ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
  2. Manually grant permission for ./var
    $ sudo chown -R www-data /var/www/symfony/var

Remember to restart php service after change

Reference:

https://symfony.com/doc/current/setup/file_permissions.html