php apache file ownership and creation problem
I am trying to do a really basic rename of a file to another name in my code. However there seems to be some ownership/permissions problem that is stopping this working correctly.
This is my (simplified) code:
These are my permissions of the files I am trying to change:
ini_set ("display_errors", "1");
$St_Num = '7940';
$Co_Code = 'RDCO2';
This code was working, and it seemed to work when apache was the *creator* of the file. However, when I changed the ownership to 'apache' it stopped working. Does PHP/Apache have a concept of knowing who the creator of a file was? Would this stop a rename() from working?
-rw-r--r-- 1 apache dev 4065 Oct 22 17:57 7940-RDCO2-3.jpg
-rw-r--r-- 1 apache dev 4276 Oct 28 09:39 7940-RDCO2-2.jpg
-rw-r--r-- 1 apache dev 4336 Oct 28 09:39 7940-RDCO2-1.jpg
I'm stumped with this one now - any help is appreciated.
In most typical web host environments, PHP runs as an Apache module, and thus your scripts are executed under the Apache user. So if the file is owned by some other user, such as your personal login/FTP account, PHP functions such as rename() will only work on files created by another non-Apache user (e.g. you) if the file permissions include read and write for all users (666 or 777 in Linux/UNIX terms, or possibly 664 or 774 if the file owner and Apache share a user group).
So, if a file is created by your PHP script, then it is owned by the Apache user and can by default be rename()'d by it, but if created by your login user or other non-Apache user, then you need to give it the necessary permissions before your PHP script can modify it (assuming again that the script is being executed by Apache as is typically -- but not always -- the case).
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread