I would like to know the answers and explanation to the following questions:
Which user/group should own the cake files?
If different, which user/group should own the
app/tmp
folder? (and subfolders)With the right user/group, what are the correct permissions for production of both folders and files? (which also if set correctly should work on development)
Where is storing of uploaded files done and what ownership/permissions need to be set to that folder. Where should it be relative to
app/
?
I know 777 fixes errors, but I would like to set it up correctly.
I have heard 660 should be more than enough for production if everything is correctly set up.
Who needs to have read
access, who needs to have write
access and does anyone need execute
?
NOTE: I think I have found the answers and since no one has written a good answer, I will write it.If you are more knowledgeable on the topic and see errors or security issues please let me know, I will correct them.
1) CakePHP ownership
The CakePHP files should be owned by you, the user of the machine (whatever you log in with). Do not have
root
as owner!OSX: the
johnsmith
part of/Users/johnsmith
Linux: the
johnsmith
part of/home/johnsmith
2) app/tmp ownership.
As per CakePHP documentation:
Option 1:
The user owner needs to be apache's user. The group owner can be the group that you belong to, so that you also have access to this folder through finder/CLI. Do not have
root
as owner!OSX: Apache is preinstalled on OSX lately and the default user of apache is
_www
. However if you are not sure you can find it out by typing terminalps aux | grep httpd
while apache runs. The last line is the command you just typed, so look above it.Now that you know your apache user, you have to assign it to
app/tmp/
. You do this with the following command:sudo chown -R _www app/tmp/
Linux: The default user on linux is usually
www-data
with groupwww-data
. If you are not sure, useps aux | grep httpd
to find out the user andsudo chown -R _www app/tmp/
to assign ownership to apache of that folder.Option 2:
You can keep yourself as the user owner, but you set up the group owner to be the a group that apache belongs to. By default apache has it's own group, but you could create a new group and add apache to it.
OSX: The group of apache on OSX by default is the same os the user:
_www
. You then have to run the following command to se up the ownership:sudo chown -R :_www app/tmp/
. Now if you check the permissions withls -l
you should see both your username (johnsmith
) and the new group owner -_www
.Linux:* By default the group of apache is
www-data
so use the same commands to change ownership:sudo chown -R :www-data app/tmp/
.NOTE: Debian/Ubuntu use
www-data
, while CentOS usesapache
.3) Permissions
For the site to run, apache needs
read
andwrite
withoutexecute
. For you to access it (assuming you are in the group that ownsapp/tmp
) you also needread
andwrite
if you will edit manually things with terminal/finder. All other users should have no rights whatsoever. So:OSX&Linux:
sudo chmod -R 660 app/tmp/
. The-R
part is to do it recursively for all inside folders. The first6
is for the user owner (OSX:_www
or Linux:www-data
), the second6
is for the group owner (OSX:staff
or Linux:johnsmith
), the0
is for all other users/guests.NOTE: According to this pull request for CakePHP it looks like CakePHP 2.4 will have ability to create subfolders in
app/tmp/
which means it will need a7
instead of6
for the user now becoming760
.4) Uploads folder
If you want to upload files, you need a similar setup for the
img/uploads
folder, or wherever you upload. The ownership will be the same, but the permissions need to have execute rights for renaming purposes and folder creation. so the previously660
should now be760
. Also, ideally, the uploads are out of thewebroot/
directory, for which an absolute path is required.For all files in
app/tmp
and subfolders you only needrw
for the web server process and if needed to use the CLI, the console user.If someone runs console commands with a user that has super rights or is in the wrong group it messes up things because what one creates can't be read or written from the other and then there are warning or failure messages. Some people (including me when I'm too lazy) fix that with
777
:)