Skip to content

File Permissions

Arthu Santiago edited this page Nov 30, 2026 · 1 revision

File Permissions

This page sets who may read and write each part of the application. The goal is that Apache (www-data) can read the code but not change it, and can write only where it must: tmp/ (cache and temporary files) and logs/.

Before you start

The code must be installed as in Installing KeyAnyWhere.

1. Make the code read-only for Apache

Your user owns the files, the group www-data can read them, and nobody else can do anything. This also undoes the "writable by everyone" permissions that composer install gives to tmp/ and logs/.

sudo chown -R "$USER":www-data /var/www/keyanywhere
sudo chmod -R u=rwX,g=rX,o= /var/www/keyanywhere

2. Let Apache write to tmp/ and logs/

Both Apache and the CLI (kaw-cake, which runs as www-data) write here, and you may run commands as your own user too. The ACLs below give both users write access to the existing files and to every file created later, as recommended by the CakePHP book.

sudo setfacl -R -m u:www-data:rwX -m u:"$USER":rwX /var/www/keyanywhere/tmp /var/www/keyanywhere/logs
sudo setfacl -R -d -m u:www-data:rwX -m u:"$USER":rwX /var/www/keyanywhere/tmp /var/www/keyanywhere/logs

3. Check that it worked

www-data must be able to write in logs/, and must not be able to write in src/:

sudo -u www-data touch /var/www/keyanywhere/logs/.write-test && echo "logs: writable" && sudo -u www-data rm /var/www/keyanywhere/logs/.write-test
sudo -u www-data touch /var/www/keyanywhere/src/.write-test 2>/dev/null && echo "src: WRITABLE, check step 1" || echo "src: read-only"

The output should be logs: writable and src: read-only.

Note

After a git checkout or composer install (an upgrade), run steps 1 and 2 again: new files get your user's default permissions.

Next step

Generating Security Keys

Clone this wiki locally