Jump to content

File Permissions


daskunk

Recommended Posts

I have a question regarding file permissions and ownership when using the File Manager in CPANEL and running PHP scripts.

 

When I log into CPANEL with my userid, and upload a file to a folder in my public_html space using File Manager, who is the "owner" of that file? It is my userid?

 

If so, then why does this happen. If I create a PHP script which displays a link to the file I uploaded, and then I try to access that file by running the PHP script in a web browser and clicking on the link, I need to have the public (world) permission bit set. In other words if I set the file permission to 0640, I'm unable to open it via the PHP script. But if I change it to 0644, then I can read it.

 

I thought maybe it was because the PHP scripts are running under some default userid that you control, but I added this call to my script

    $username = posix_getpwuid(posix_geteuid())['name'];

and it tells me that the PHP script is executing under my userid (the same one I use to log into CPANEL and upload the file). So if my userid owns the file, and my userid is executing the PHP script, then why do I need 0644? Why isn't 0640 sufficient?

 

Sorry if it's a stupid question, but I'm used to being able to ls -altr on a linux box in order to see the owners of all the files in a directory, but with the CPANEL File Manager I can only see the permissions of the files.

 

Thanks very much

Link to comment
Share on other sites

My guess is that apache has to read the file first in order to pass it to php. Apache runs as the user nobody so it needs other readable permissions to even see the php script. Then once the php script is passed to php it is executed as your userid. I suspect if you ran a cronjob on a php script with 640 permissions it would work.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...