Could anyone help me with some unix permission stuff? I’ve been struggling with it for months now and can’t get it quite right.
My web server is running as www-data
in the www-data
group and I do my composer stuff as a user called finn
with sudo privileges (but I definitely don’t sudo composer :joy:).
From what I read, it is often easier for a user to own all the files/directories but for the user to be in the www-data
group, so to that effect I have written a bash script:
#!/bin/bash
sudo chown -R finn:www-data /srv/pyrocms
sudo usermod -a -G www-data finn
sudo find /srv/pyrocms -type f -exec chmod 664 {} ;
sudo find /srv/pyrocms -type d -exec chmod 775 {} ;
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
Where the aim is to
1. Make me own everything
2. Add me to the www-data
group
3. Set read/execute permissions
4. Change the group to www-data
for the all important storage
and bootstrap/cache
5. Give me and the www-data
group read/write/execute permissions on storage
and bootstrap/cache
The problem!
After doing composer update
as the finn
user I often get problems where the web server cannot write to cache files in storage/streams/{site-slug}/cache/
and it kicks the bucket throwing 500 errors.
What can I do to fix this?
2
Answers
Since you already have sudo privileges and you’re using sudo, it may be easier to login as
www-data
user and do all tasks aswww-data
. There will be no problems with privileges if everything will be owned bywww-data
:Alternatively (and probably better) option would be to create dedicated user (like
www-finn
) and always run PHP aswww-finn
. It should be pretty easy to achieve, if you’re using php-fpm for running PHP processes for handling web requests:Add
www-data
towww-finn
group so webserver will have access towww-finn
files. And then makewww-finn
owner of your web app:You should run
composer create-project pyrocms/pyrocms pyrocms
from/home/finn/srv
folder and underfinn
and definitely NOT sudo user (finn
may be sudoer or not it is don’t matter).PHP-FPM pool config:
Nginx host config:
Then you may not change any permissions under your
finn
unix user, but if there would be troubles, just run next underfinn
user:Also, please notice about you would need sudo only for edit your configs under
/etc
folder.