Symfony2 file permissions in Ubuntu

The installation section of The Book has a section on setting up permissions. This walks through the process of setting up the cache and log directories so that both you and your webserver may modify their contents.

It says to first try and use chmod because that is, it claims, how most systems controls their ACLs. This is only true for Mac OSX however. For Unix and Linux based ones, ACL is actually controlled using setfacl.

Install and enable ACL

First you need to install ACL, preferrably through your package manager; aptitude on Ubuntu, pacman on Arch, yum on Fedora, etc:

$ sudo aptitude install acl

Then you edit your /etc/fstab to enable ACL for your partition. Simply add acl to the list of options.

/dev/sda1 / ext4 rw,auto,acl 0 1

Then lastly remount the partition to have the new options take effect.

$ sudo mount -o remount /

Now you have ACL enabled for your partition. The next step is to configure it for your cache and log directories, so all users can modify the files and directories within.

$ sudo setfacl -dR -m u::rwX app/cache app/logs

Encrypted home directory

When I installed Ubuntu I opted in to use the "encrypt home directory" feature. This makes use of eCryptFS and it turns out this file system lacks support for ACL.

So what is a tin foil, Ubuntuist, Symfonian hatter to do?

The solution I used was to set up a /symfony/project-name directory, in which I created a cache and a log directory. Then I symlinked these to the project in my home directory.

$ ln -s /symfony/nogfx/cache /home/tobias/projects/nogfx/app/cache
$ ln -s /symfony/nogfx/log /home/tobias/projects/nogfx/app/log

Because they actually exist in my root partition I can easily enable ACL for them, while reaping the benefits of using Symfony CLI on my encrypted home!