Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am setting up my site, and I need to move some files around. I created a simple PHP script that involved things like mkdir(), copy() etc...but I am getting permissions errors.

After setting affected folders to 777 everything works, but on my old site I was set 755.

If my user in Plesk is Johnnie, and the user on the file is Johnnie (and the group is psacln) shouldn't the PHP script have access? If not, what do I need to set the user as for my browser to be able to move files around?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

What do you mean by access? - to see the file attributes; - to open the file for reading; - to open the file for writing; - to open the file for read/write; - to open the file for execute.

Please note that the username in the PHP application it is not the same as the Unix user even if they have the same name.

Please take note that apache/php is running as apache, www, www-data, nobody... user. This is configured in apache configuration. Find this with:

egrep -r '^User|^Group' /etc/{apache*,http*}

Before any change run a backup.

Find a common group your user and apache user are part of. If not create one.

Change the group of the files and folders that you have in DocumentRoot to be this group:

chown -R myuser:commongroup /var/www/

Change the SUID of the folders so that new files are owned by that group:

find /var/www/ -type d -print0|xargs -0r chmod g+rxs
chmod -R u+r,g+r,o= /var/www/

For the folders and files you want to give access to PHP for writing do:

chmod g+w /var/www/folder/subfolder   /var/www/folder/file.txt
share|improve this answer

If you are using php via cgi or mod-php without additional patches/modules to deal with permissions then your php script is probably being executed with the web server's account. This is frequently www-data, nobody, or some other non-root account.

You probably need to add the user the web server is running as to the group, or create a group that includes includes the web server and any other users that need access.

share|improve this answer
    
zoredache...cool...is there any way to know for sure my web server's user? i am using linux centos w/ plesk if that helps at all...thanks:) –  johnnietheblack Jan 22 '10 at 0:08
    
Look at the apache configuration file. The egrep command mentioned by Mircea Vutcovici should do that. –  Zoredache Jan 22 '10 at 0:36

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.