PHP Scripts and Creating Files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bryan  Meyer

    PHP Scripts and Creating Files

    Hello Everyone:

    I have a PHP script that attempts to create a temporary file to be used
    during processing. The script is owned by my username (bryanrme) on
    the server. When the script attempts to create the temporary file, I
    get a "failed to open stream: Permission denied" error. The
    permissions on my directory are set to 755. When I set the permissions
    to 757, the creation of the file is successful. In this case, I notice
    that the script spawns a temporary file owned by a user named "99".

    Is there any way to avoid this? I'd prefer not to leave my directory
    set at 757, but is there any workaround for this? I checked my server
    configuration and safe mode is not enabled. Any suggestions? I would
    prefer that the script handle the creation, usage, and disposable of
    the temporary file.

    Thanks,
    Bryan

  • Geoff M

    #2
    Re: PHP Scripts and Creating Files

    brmeyer@gmail.c om says...
    [color=blue]
    > I have a PHP script that attempts to create a temporary file to be used
    > during processing. The script is owned by my username (bryanrme) on
    > the server. When the script attempts to create the temporary file, I
    > get a "failed to open stream: Permission denied" error. The
    > permissions on my directory are set to 755. When I set the permissions
    > to 757, the creation of the file is successful. In this case, I notice
    > that the script spawns a temporary file owned by a user named "99".
    >
    > Is there any way to avoid this? I'd prefer not to leave my directory
    > set at 757, but is there any workaround for this? I checked my server
    > configuration and safe mode is not enabled. Any suggestions? I would
    > prefer that the script handle the creation, usage, and disposable of
    > the temporary file.[/color]

    (assuming you mean the script is run via a web interface and that this is
    a Linux/Apache setup)

    PHP runs scripts under the umbrella of the Apache user (looks like this is
    user 99 in your setup) with the permissions/etc for that user.

    Set up a user group with both (and only) yourself and the Apache user as
    members. Set the directory's group ownership to this group (leave the
    directory's personal ownership as yourself). Set directory permissions to
    775.

    Geoff M

    Comment

    • Bryan  Meyer

      #3
      Re: PHP Scripts and Creating Files

      Geoff:

      Thanks for the advice. Unfortunately, it is not my server. I purchase
      hosting. I access my settings through the cPanel interface, so I'm not
      sure if there is any way to follow the instructions you gave me. Is
      there a way?

      Bryan

      Comment

      • Geoff M

        #4
        Re: PHP Scripts and Creating Files

        brmeyer@gmail.c om says...
        [color=blue]
        > Thanks for the advice. Unfortunately, it is not my server. I purchase
        > hosting. I access my settings through the cPanel interface, so I'm not
        > sure if there is any way to follow the instructions you gave me. Is
        > there a way?[/color]

        Bryan,

        If your willing to try ....

        Use the SSL Shell/Telnet shell access button (near bottom of cPanel page?)
        and when you have logged in and have a command line prompt and type in:
        groups 99
        to see the list of user groups that the user named 99 (which Apache/PHP
        appears to be running as) belongs to.

        Then type in:
        groups <your account name>
        and see what groups you are in.

        If you're lucky, there might be a group common to you both. Even if not,
        you could still just pick a group that user 99 belongs to (less secure,
        but hey, still better than world writable) and you may be able to set the
        directory's group ownership to that group.

        To see who might be members of a group, type in:
        cd /etc/
        then type in
        more group | grep <group name>

        Navigate to one level above the relevant directory:
        cd /<path to your directory>/

        Typing in:
        ls -al
        will give you details of directories and files including their user and
        group ownership settings.

        You can leave the relevant directory personally owned by you and just
        change the group ownership by typing:
        chgrp <group name> <directory name>

        Again type:
        ls -al
        to check that the change has worked, then type:
        chmod 775 <directory name>
        and then PHP will be able to write to the directory.

        G

        Comment

        Working...