Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I gave permissions to read and write files in /var/www to the working user(me) through the steps given in Whats the simplest way to edit and add files to “/var/www”?. It works fine when I try to create/read file in the project directory.

Say I am working in /var/www/xyz

I am able to read and write files in this folder through a php code. Now, I have created a folder inside folder xyz, say abc

/var/www/xyz/abc

In my php code when I read a file situated inside abc, it works fine, but it gives me warning: permission denied when I try to create a file in this folder.

The exact warning is

Warning: fopen(abc/a.txt): failed to open stream: Permission denied in /var/www/xyz/code.php

I was asked to provide some output:

stat /var/www/dodge
  File var/www/dodge' 
  Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 700h/1792d Inode: 1445503 Links: 8
Access: (2775/drwxrwsr-x) Uid: ( 33/www-data) Gid: ( 33/www-data)
Access: 2013-07-16 16:29:21.434531583 +0530
Modify: 2013-07-16 14:07:46.482782580 +0530
Change: 2013-07-16 16:28:04.622533850 +0530
 Birth: -

stat /var/www/xyz/abc
  File: /var/www/dodge/codes' 
  Size: 4096 Blocks: 8 IO Block: 4096 directory 
Device: 700h/1792d Inode: 1446465 Links: 2 
Access: (0775/drwxrwxr-x) Uid: ( 1000/ wq) Gid: ( 1000/ wq) 
Access: 2013-07-16 15:16:15.554661170 +0530 
Modify: 2013-07-16 15:13:42.698665686 +0530 
Change: 2013-07-16 15:13:42.698665686 +0530
 Birth: -
share|improve this question
    
What is the output of stat /var/www/xyz /var/www/xyz/abc? –  Grzegorz Żur Jul 16 '13 at 11:21
    
I just found out that the directory xyz has socket(s) permission. But the directory abc only has directory(d) permission. –  vinit Jul 16 '13 at 12:23
    
Welcome to Ask Ubuntu! The best way to add additional information to your question is by editing it, with the edit button. It is better visible that way, and comments are mainly for secondary, temporary purposes. Comments are removed under a variety of circumstances. Anything important to your question should be in the question itself. –  guntbert Jul 16 '13 at 21:19
    
Include the ls -l output on the folder in question as an edit to your question. –  Thomas W. Jul 16 '13 at 21:21
add comment

2 Answers

For this situation you need set set-group-ID bit on directory /var/www/xyz so newly created directories inside inherit group from parent.

chmod g+s /var/www/xyz

See man 2 chmod

S_ISGID (02000) set-group-ID (set process effective group ID on execve(2); mandatory locking, as described in fcntl(2); take a new file's group from parent directory, as described in chown(2) and mkdir(2))

See comments to the answer from refferred post.

It seems you change SGID on 16:28 but the code directory was created earlier. Either recreate it or set its group correctly.

chown xxx:group /var/www/dodge/code

SGID bit works when you create new files and directories. It will not work for already created.

share|improve this answer
    
Its not working. Still the same warning permission denied –  vinit Jul 16 '13 at 11:07
add comment

Solved this issue by adding the folder xyz to the group var-www. Thus, now I am able to write to the files in the sub-folders too

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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