Results 1 to 2 of 2

Thread: php apache file ownership and creation problem

Hybrid View

  1. #1
    Join Date
    Apr 2006

    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:

    PHP Code:
    ini_set ("display_errors""1");

    $St_Num '7940';
    $Co_Code 'RDCO2';

    These are my permissions of the files I am trying to change:

    -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
    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?

    I'm stumped with this one now - any help is appreciated.


  2. #2
    Join Date
    Aug 2004
    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).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center