Page 1 of 1

how upload using php code with file permissions in ubuntu

PostPosted: 31. March 2020 05:56
by sreekar1
how upload using php code with file permissions in ubuntu

Re: how upload using php code with file permissions in ubunt

PostPosted: 31. March 2020 11:14
by Nobbie
The target/upload folder must have sufficient rights to allow Apache to create files in that folder. Apache (and PHP) runs with the User and Group as defined in httpd.conf. The file itself should have sufficient rights for Apache to read it, if it is used for HTTP Request later on.

The default rights for a newly created file are defined by the "umask" command in Linux. It is the umask in the context of the Apache User (see above). In new Xampp installations usually the User is set to "daemon", same for the Group. See the manual for umask. You can modify file rights after upload in the upload PHP script via chmod() function: https://www.php.net/manual/en/function.chmod.php

You may also change User and Group of Apache to your needs, for example i created a new User "xampp" in my Linux and assigned Apache to run with "xampp". I also changed ownership of htdocs to "xampp" etc., I also assigned the htdocs folder as home folder for User "xampp", then finally i can use FTP Server with User "xampp" to put files via FTP onto my htdocs folder (some tools like WordPress need that).