I frequently find myself encountering problems (usually permissions) when trying to setup a local development server. Or creating a new site (alias).

Very common problem is I need to allow www-data (Apache use on ubuntu) access to all directories leading to the working directory.

Another problem is since I am logged in as my personal user jiewmeng, when I create new files, they are owned by me, and sometimes, Apache can't read/write to it.

How is your local development setup like? I am using Ubuntu 11.10.


I frequently find myself encountering problems (usually permissions)

That rather implies that you haven't got a permissions model in place.

How is your local development setup like?

I use the 'other' entity to allow access for the apache uid, the 'group' is for the people who need to deploy / edit files and the user is the user whom created the files.

So my files look something like:

drwxrwsr-x symcbean webdev  webroot/
-rw-rw-r-- other    webdev  webroot/a.php
-rw-rw-r-- symcbean webdev  webroot/b.php
drwxrwxrwx symcbean webdev  webroot/data
-rw-rw-rw- apache   apache  webroot/data/stuff.txt
drwxrwsr-x symcbean webdev  webroot/include/
-rw-rw-r-- symcbean webdev  webroot/include/def.php
  • I am new to Linux, so I still learning as I go. So when I create new users, I should do something like adduser {username} --gid www-data to make the files they create under the www-data group (then apache can see those)? For existing users, I'd do usermod --gid www-data {username}? Is gid meant for that? I was wondering how can I have files I create under www-data – Jiew Meng Dec 23 '11 at 13:03
  • 1
    For existing users, do not forget the --append option or you clear all groups – Lekensteyn Dec 23 '11 at 14:04
  • Oh then do you have all your files in web root. I think another problem I need to allow www-data I think rwx access on parent folders all the way down to the project. Perhaps in a production environment I can put all my files in web root, but in development, I think its better to put them in the data drive, or /projects. Also when using frameworks, I think its a good practice to have my application files outside webroot – Jiew Meng Dec 31 '11 at 3:41
  • To clarify, @JiewMeng, I don't think @@symcbean was saying anything about adding {username} to www-dev. That is one way of doing it, but not what @@symcbean was suggesting. @@syncbean was suggesting that you create a new group called webdev so that others users as well can be added to that group. Then, if you group-own all files and folders by webdev, all your users can edit those files. How does apache aka www-data access the files it needs? That's what he meant by "other" permissions (aka "world" permissions)—the last triad—as long as apache can read files and – Andrew Cheong May 1 '14 at 19:52
  • read/execute directories, that's all it needs. (Even for things like PHP files, Apache only needs to be able to read them.) In @@symcbean's model, the significant thing is the sticky bit on the directories (notice the s in lieu of x) that instructs new files and directories to inherit its group. And that's how your users continue to have access to files and directories as they get created. Finally, you notice there's a directory without an s, and a file in it owned by apache aka www-data. That's an example of how you'd configure an "uploads" folder—@@symcbean calls it "data." – Andrew Cheong May 1 '14 at 19:55

I'm using Solution 1 (the setgid method) described on How to avoid using sudo when working in /var/www? This has as advantage that I can read files created by Apache and the other way round.

  • So all your scripts / content is writeable by the webserver uid? – symcbean Dec 23 '11 at 11:49
  • @symcbean It's readable only unless I manually chmod g+w a file or directory. – Lekensteyn Dec 23 '11 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.