My doubts with folder Permissions

Discussion in 'PHP' started by digitalphoenix, Sep 12, 2007.

  1. #1
    Recently i uploaded an image hosting script at hostgator.The script worked perfectly even when the permissions of the "files"directory(the directory to which the uploaded file was to be move using move_uploaded_file function) was set to 755 (no write permissions for public and group).But the same script was uploaded to a dedicated server .But the move_uploaded_file function threw an error when folder permission for "files" folder was set to 755 ,and only worked whn it was set to 777.

    Why does it work smoothly at hostgator with a 755 and doesnt work at my new host with a 755?

    Please help me solve this
    Thanks
     
    digitalphoenix, Sep 12, 2007 IP
  2. k2pi

    k2pi Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try with 766, if it works it migth be more secure
     
    k2pi, Sep 13, 2007 IP
  3. fabriciogr

    fabriciogr Active Member

    Messages:
    958
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    73
    #3
    if 777 works and 755 doesn't work that's a ownership issue and not a permissions issue..

    you need to chown (change ownership) to the right user.. usually something like

    chown - R nobody:nobody folder_in_doubt


    and set permissions back to 755... don't ever have 777 ur just begging someone to hack u :mad:
     
    fabriciogr, Sep 13, 2007 IP
  4. digitalphoenix

    digitalphoenix Peon

    Messages:
    467
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    the owner is set to the cpanel login.is it correct?
     
    digitalphoenix, Sep 14, 2007 IP
  5. fabriciogr

    fabriciogr Active Member

    Messages:
    958
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    73
    #5
    well i can't really say if it's right or not since i'm not logged into the server and can't check all user groups..

    here are a few steps u can do to get ur script working. it's going to be a few steps going back and forth but it'll help u out

    1. temporarily set the folder where u want to upload to 777:
    chmod 777 folder_to_upload_to

    2. immediately (all these following steps try to do asap as we're leaving a hole in ur site with that 777 :eek:) go to ur site and upload the image and in this instance it should work as the folder is completely writeable

    3. cd into the directory where the image or file was uploaded and do: "ls -al"

    4. pay attention to the user and group that recently uploaded file has... the listing should be something like this:

    -rw-r--r-- 1 userHere groupHere 660 Sep 13 14:23 uploaded_file.png

    usually with CPANEL the user is nobody and group is nobody.

    5. cd up one level : cd ..

    6. now you can set the right user and ownership to your folder.. via:

    chown -R userHere:groupHere folder_to_upload_to

    7. now lets set permissions back to 755: chmod 755 folder_to_upload_to
    ** now we're safe again.. no longer hackable... :)

    8. finally go back to ur site and try to upload the image again.. and this time it should work lovely...

    hope this makes sense and helps..
     
    fabriciogr, Sep 14, 2007 IP
  6. digitalphoenix

    digitalphoenix Peon

    Messages:
    467
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks for taking time to help me fabriciogr

    Can u say me where to enter all the commands like chown and ls -al in CPANEL 11
     
    digitalphoenix, Sep 14, 2007 IP
  7. fabriciogr

    fabriciogr Active Member

    Messages:
    958
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    73
    #7
    ok... forgot to mention that.. do u have ssh access??

    do u only have cpanel or whm?
     
    fabriciogr, Sep 14, 2007 IP
  8. digitalphoenix

    digitalphoenix Peon

    Messages:
    467
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I have a link in cpanel called SSH/SHELL ACCESS.But it has options for creating and managing keys.It does not have a java ssh client which was shown in the video tutorial of cpanel
     
    digitalphoenix, Sep 14, 2007 IP
  9. fabriciogr

    fabriciogr Active Member

    Messages:
    958
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    73
    #9
    ok no worries as it seems that u might have at least SSH access granted..

    download Putty

    and login to ur server via ur IP Address and u can probably use the same user and password u user for CPANEL...

    let me know how this goes.
     
    fabriciogr, Sep 15, 2007 IP