开发者

group and owner permissions are wrong when php uploads files

开发者 https://www.devze.com 2023-04-12 03:00 出处:网络
Not sure if this is a php configuration or linux file permission issue. The problem I\'m having is when a file is uploaded through php using move_uploaded_file() into the directory which has group set

Not sure if this is a php configuration or linux file permission issue. The problem I'm having is when a file is uploaded through php using move_uploaded_file() into the directory which has group set to ubuntu and owner set to www-data, the uploaded file owner and group permissions change to www-data which causes problems for my python script to come in and perform its task on the uplo开发者_StackOverflow中文版aded file.

example:

move_uploaded_file($tempFile,$targetSAVE);

--$targetSAVE directory is set to:

group: ubuntu
owner: www-data
permissions: 0755

--php uploaded file changes owner and group to www-data

new file changes to:
  group: www-data  <-- need this set to *ubuntu*
  owner: www-data
  permissions: 0755

--python script needs the group of the uploaded file set to ubuntu

how can I configure php to to set ownership or group of uploaded file to ubuntu or if this is a linux file permission issue how can i fix this?

All directories and sub directories are set to: group: ubuntu owner: ubuntu permissions: 0755 except the directory the files are being uploaded to, this is set to:

group: ubuntu
owner: www-data
permissions: 0755 


Found the solution. After pulling my hair out and trying all other responses it turned out to be very simple here's what worked.

chown -R ubuntu:www-data /var/www/
chmod -R 775 /var/www/

After that the python script executed perfectly from php.


This is happening because PHP runs as the user that runs the web server. In effect all websites on your system will run as this user/group and therefore all have access to read eachother's files and directories created by php scripts.

Installing Apache mod suPHP is probably the easiest solution to this problem. This will allow you to run php scripts in a virtual host as a specific user and group. You could also run PHP as a CGI and use Apache suEXEC but this is a bit more complicated to set up that suPHP.

Alternatively, you should just be able to chown files from your scripts to the appropriate user/group, but the effect will be that the web server no longer can read/edit those files once you change ownership of them.


I guess I'd just add a chirp directive at the end of the PHP script, if that will work in your case. http://us.php.net/manual/en/function.chgrp.php

Look in /etc/passwd to get the numerical ID for the "ubuntu" user.

Note from the docs: "Only the superuser may change the group of a file arbitrarily; other users may change the group of a file to any group of which that user is a member."

0

精彩评论

暂无评论...
验证码 换一张
取 消