Jump to content

php file write permissions. HOW?


inversesoft123

Recommended Posts

I found that on some servers users or scripts can write into files without having universal write premissions 777. but on some servers 777 chmod must be there to write into file.. why like this?

 

Is there any settings into cpanel or WHM to enable this stuff or this is based on PHP version..

please help

 

thx is advance.

 

:)

Link to comment
Share on other sites

777 is read/write/execute for everybody

you can set user and group permissions also. You can do this in in cpanel's file manager.  Right click on the folder and go to permissions.    Set read/write/execute for user only    then only the webuser which is what php runs under will be able to upload files.

Link to comment
Share on other sites

777 is read/write/execute for everybody

you can set user and group permissions also. You can do this in in cpanel's file manager.  Right click on the folder and go to permissions.    Set read/write/execute for user only    then only the webuser which is what php runs under will be able to upload files.

 

ya agreed but on some servers we can upload files without assigning read write execute (777) to folder hows that ?

Link to comment
Share on other sites

I can only think of bad server set-up.

 

ohhh.. Previously my websites ware hosted on HostICan VPS and my team uploaded thousands of files and folders and text databases without 777 and sites ware working fine. But now I moved to dedicated and there are lots of permission denies on site... I think we need to correct them manually. :-\

Link to comment
Share on other sites

4 = r-- =  read

2 = -w- = write

1 = --x = execute

=>

7 = 4+2+1 = rwx = read+write+execute

6 = 4+2 = rw- = read+write

5 = 4+1 = r-x = read+execute

3 = 2+1 = -wx = write+execute

0 = --- = no permissions

 

x1x2x3 = owner, group, other

 

-[---][---][---]

|  |    |    '----> other

|  |    '---------> group

|  '--------------> owner

'-----------------> other stuff I won't explain here

 

=> 664 = rw-rw-r-- = owner/group: read+write; other: read

 

So if file.php has owner daniel and group apache and it has 664 then my my user and the group apache (which your webserver could use) can read and write to and from that file. Everybody else can only read.

 

Each file and directory has an owner and a group, and each running process will have an owner and group. In order to be allowed to perform an operation (i.e. read, write or execute) the process will have to satisfy at least one of owner, group or other permission masks.

 

There is also something called setuid and setgid. Say for instance that foo.sh is owned by root and has has setuid. Whenever this file is executed it'll now be run as root, even if the user running it isn't root. Same thing for setgid only with groups instead. Then there is "sticky bit" which, when set on directories, ensures that only the owner of a file will be able to move or delete that file.

 

Why someone can or cannot write to a file depends on all the above. You can find more information in the man pages or using Google.

Link to comment
Share on other sites

  • 10 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.