SuPHP move_uploaded_file fileperms to 600 instead of 644

Discussion in 'Tips/Tricks/Mods' started by ethanlifka, Mar 7, 2010.

  1. ethanlifka

    ethanlifka New Member

    Its your /tmp directories - More info below

    It seems that when you use move_uploaded_file() with SuPHP or FastCGI with SuExec the File Permissions are being set to 600 instead of 644.

    This means any readable files like images, text, etc or not accessable by http. You need at least 640 to have be accessable by http.

    At first everyone said it can be set in /etc/suphp.conf.
    Change umask to 0022 instead of 0077.
    Then restart apache.

    FYI, if you are using FastCGI with suExec you can set umask in your sites ".php-fcgi-starter" file by adding "umask 0022"
    umask 0022
    export PHPRC
    NOTE: You can also edit "/usr/local/ispconfig/server/conf/php-fcgi-starter.master", but be asure to edit it directly and not FTP. Editing master files with FTP may result in PHP Parsing Errors.

    Well my umask was already 0022. So this was not the solution for me.
    Then everyone said just use chmod() after move_uploaded_file(). Which works great, but is not a good solution for big hosting companies who want to easily migrate multiple sites to their server. Having to change so much php code can be overwhelming.

    After more research I found that it is not suphp.conf because the umask setting does work. Try mkdir() or fwrite(). Files and directories are set to 755 and 644 just fine. It's not the move_uploaded_file() function either.

    It's your /tmp directories. Any files created in them are set to 600. The HTTP FILES Upload uses your sites /tmp to upload the file to. Not sure where the source of this 600 fileperms setting is coming from. Maybe your OS, maybe suPHP or suExec core.

    If you know then please respond !!!!!!

    I believe it is a security feature to not have any files in /tmp readable, writable, or executable by anyone other then the owner.

    So when you use move_upload_file() it keeps the fileperms that where originaly set by the /tmp directory or your sites /var/www/ directory.

    if you use copy() instead of move_uploaded_file() then it will generate 644 instead of 600.

    Hope this helps.

    I am still looking for a solution to automaticly set files to 644 with and only using move_uploaded_file().

    Is it possable to rewrite the move_uploaded_file() function or append the chmod() after it?
    Last edited: Mar 7, 2010
  2. grungy

    grungy Member

    I am having the same issue....with php-fastcgi, did you figure out this?
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    You can set the umask in the fcgi starter for this website file as explained in the above post. You might also want to change that in the fcgi starter file template in /usr/locals/ispconfig/server/conf/ as well.
  4. grungy

    grungy Member

    Setting umask to 0022 did not work....
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    In which files did you set it? Please post the files.
  6. grungy

    grungy Member

    # cat /var/www/php-fcgi-scripts/web32/.php-fcgi-starter
    umask 0022
    export PHPRC
    # The variable PHP_FCGI_CHILDREN is onyl useful for lighty or nginx as apache 
    # mod_fcgi will control the number of childs themself and never use the additional processes.
    # export PHP_FCGI_CHILDREN
    exec /usr/bin/php-cgi \
  7. till

    till Super Moderator Staff Member ISPConfig Developer

    Ok. Did you restart apache after you changed that file?
  8. grungy

    grungy Member

    Yes I did restart apache
  9. grungy

    grungy Member

    Not sure if this is important but this is the content of my /tmp folder

    # ls -all /tmp/phpsYq9OZ
    -rw------- 1 web19 client23 3771 Feb 13 18:22 /tmp/phpsYq9OZ
    I listed temp files only for targeted domain...the temp file has 600 permission just like the uploaded images :(
  10. darkangel

    darkangel New Member

    This doesn't work for me either ... did anyone get it working?
  11. darkangel

    darkangel New Member

    Got it working (for PHP sessions) ... you have to change the file mode for the session save path, e.g.:

    session.save_path = "0;0660;/path/to/sessions"

    And also remove the following line from the .php-fcgi-starter file:

    -d session.save_path=/path/to/tmp \

    ... because it overwrites anything you set in your custom php.ini settings (bug?).


Share This Page