Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Apache + PHP require execution permissions to write to a file?

It has always baffled me that if a folder has read and write permissions, Apache + PHP can't write to it. You have to end giving apache execution permissions to be able to write a file in that folder. Why?

For example with chmod 664 (where the build group includes the apache user) apache won't be able to write a temporary cache file in this folder:

drw-rw-r--  5 jenkins build 4096 Jun 15 13:05 cache

while with chmod 774 apache will be able to write a new file to the folder:

drwxrwxr--  5 jenkins build 4096 Jun 29 11:44 cache
like image 465
tomwoods Avatar asked Jun 29 '12 17:06

tomwoods


2 Answers

You need execute permission to conceptually enter a directory (cd into it, list files within, etc.). It would have been clearer if they called this bit something else for directories. This article recommends thinking of it as the "search" permission on directories.

like image 76
Matthew Flaschen Avatar answered Nov 03 '22 11:11

Matthew Flaschen


When these permission are set for a directory it gives ability to access metainfo and accessing to contents I think this is why you need execute.

like image 38
PoX Avatar answered Nov 03 '22 10:11

PoX