permission denied - fopen

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

    permission denied - fopen

    What can cause the PHP code fopen("filename ","a") to fail with
    permission denied message as below?
    ------------------
    Warning: fopen(filename) : failed to open stream: Permission denied in
    /home/lookout/u2/kmei/www/test1.php on line 14
    ------------------
    I write a short PHP code that works fine on my own apache server, but it
    doesn't work after I upload it to the university server. Note that
    'chmod 777 filename' works as expected.

    thanks
  • Senator Jay Billington Bulworth

    #2
    Re: permission denied - fopen

    bird <bird@village.o rg> wrote in news:cv688a$jn$ 1
    @mailhub227.itc s.purdue.edu:
    [color=blue]
    > What can cause the PHP code fopen("filename ","a") to fail with
    > permission denied message as below?
    > ------------------
    > Warning: fopen(filename) : failed to open stream: Permission denied in
    > /home/lookout/u2/kmei/www/test1.php on line 14
    > ------------------[/color]

    Hi,

    It's a permissions issue one way or another.
    [color=blue]
    > I write a short PHP code that works fine on my own apache server, but[/color]
    it[color=blue]
    > doesn't work after I upload it to the university server. Note that
    > 'chmod 777 filename' works as expected.
    >
    > thanks[/color]

    This is odd. I am assuming that there is a file named "filename" in
    /home/lookout/u2/kmei/www/ and that this is the file you have chmod 777?

    hth


    --
    Bulworth : PHP/MySQL/Unix | Email : str_rot13('f@fu ng.arg');
    --------------------------|---------------------------------
    <http://www.phplabs.com/> | PHP scripts, webmaster resources

    Comment

    • bird

      #3
      Re: permission denied - fopen

      Senator Jay Billington Bulworth wrote:[color=blue]
      > bird <bird@village.o rg> wrote in news:cv688a$jn$ 1
      > @mailhub227.itc s.purdue.edu:
      >
      >[color=green]
      >>What can cause the PHP code fopen("filename ","a") to fail with
      >>permission denied message as below?
      >>------------------
      >>Warning: fopen(filename) : failed to open stream: Permission denied in
      >>/home/lookout/u2/kmei/www/test1.php on line 14
      >>------------------[/color]
      >
      >
      > Hi,
      >
      > It's a permissions issue one way or another.
      >
      >[color=green]
      >>I write a short PHP code that works fine on my own apache server, but[/color]
      >
      > it
      >[color=green]
      >> doesn't work after I upload it to the university server. Note that
      >>'chmod 777 filename' works as expected.
      >>
      >>thanks[/color]
      >
      >
      > This is odd. I am assuming that there is a file named "filename" in
      > /home/lookout/u2/kmei/www/ and that this is the file you have chmod 777?
      >
      > hth
      >
      >[/color]
      Yes, the file I want to write in the PHP code is exactly the file
      changed its mode to 777. I wonder if the administrator has some special
      way to overrule my file mode.

      Comment

      • Jeb Hunter

        #4
        Re: permission denied - fopen

        who owns the folder?

        --

        "bird" <bird@village.o rg> wrote in message
        news:cv7de8$baj $1@mailhub227.i tcs.purdue.edu. ..[color=blue]
        > Senator Jay Billington Bulworth wrote:[color=green]
        > > bird <bird@village.o rg> wrote in news:cv688a$jn$ 1
        > > @mailhub227.itc s.purdue.edu:
        > >
        > >[color=darkred]
        > >>What can cause the PHP code fopen("filename ","a") to fail with
        > >>permission denied message as below?
        > >>------------------
        > >>Warning: fopen(filename) : failed to open stream: Permission denied in
        > >>/home/lookout/u2/kmei/www/test1.php on line 14
        > >>------------------[/color]
        > >
        > >
        > > Hi,
        > >
        > > It's a permissions issue one way or another.
        > >
        > >[color=darkred]
        > >>I write a short PHP code that works fine on my own apache server, but[/color]
        > >
        > > it
        > >[color=darkred]
        > >> doesn't work after I upload it to the university server. Note that
        > >>'chmod 777 filename' works as expected.
        > >>
        > >>thanks[/color]
        > >
        > >
        > > This is odd. I am assuming that there is a file named "filename" in
        > > /home/lookout/u2/kmei/www/ and that this is the file you have chmod 777?
        > >
        > > hth
        > >
        > >[/color]
        > Yes, the file I want to write in the PHP code is exactly the file
        > changed its mode to 777. I wonder if the administrator has some special
        > way to overrule my file mode.[/color]


        Comment

        • News Me

          #5
          Re: permission denied - fopen

          bird wrote:[color=blue]
          > Senator Jay Billington Bulworth wrote:
          >[color=green]
          >> bird <bird@village.o rg> wrote in news:cv688a$jn$ 1
          >> @mailhub227.itc s.purdue.edu:
          >>
          >>[color=darkred]
          >>> What can cause the PHP code fopen("filename ","a") to fail with
          >>> permission denied message as below?
          >>> ------------------
          >>> Warning: fopen(filename) : failed to open stream: Permission denied in
          >>> /home/lookout/u2/kmei/www/test1.php on line 14
          >>> ------------------[/color]
          >>
          >>
          >>
          >> Hi,
          >>
          >> It's a permissions issue one way or another.
          >>
          >>[color=darkred]
          >>> I write a short PHP code that works fine on my own apache server, but[/color]
          >>
          >>
          >> it
          >>[color=darkred]
          >>> doesn't work after I upload it to the university server. Note that
          >>> 'chmod 777 filename' works as expected.
          >>>
          >>> thanks[/color]
          >>
          >>
          >>
          >> This is odd. I am assuming that there is a file named "filename" in
          >> /home/lookout/u2/kmei/www/ and that this is the file you have chmod 777?
          >>
          >> hth
          >>
          >>[/color]
          > Yes, the file I want to write in the PHP code is exactly the file
          > changed its mode to 777. I wonder if the administrator has some special
          > way to overrule my file mode.[/color]

          I think Jeb hit the nail on the head: in order to modify a file, you
          need write access to both the file AND the dir that contains it.

          --
          convert UPPERCASE NUMBER to a numeral to reply

          Comment

          • bird

            #6
            Re: permission denied - fopen

            Jeb Hunter wrote:[color=blue]
            > who owns the folder?
            >[/color]
            The folder modes is as below:
            ----------------------------------
            drwxrwxrwx 9 kmei student 4096 Feb 18 22:31 www
            ----------------------------------
            The parent of 'www' is my home on the server. please see the path:
            /home/lookout/u2/kmei/www/test1.php
            'kmei' is my ID on the server.

            thanks again.

            Comment

            • bird

              #7
              Re: permission denied - fopen

              bird wrote:[color=blue]
              > Jeb Hunter wrote:
              >[color=green]
              >> who owns the folder?
              >>[/color]
              > The folder modes is as below:
              > ----------------------------------
              > drwxrwxrwx 9 kmei student 4096 Feb 18 22:31 www
              > ----------------------------------
              > The parent of 'www' is my home on the server. please see the path:
              > /home/lookout/u2/kmei/www/test1.php
              > 'kmei' is my ID on the server.
              >
              > thanks again.[/color]
              A couple of other details I want to provide here. Maybe there are
              helpful for you guys to diagnose.

              1) I initially wrote the code with perl. That code worked for more than
              one year, but it doesn't work any more since a few weeks ago. I found
              the perl code open (handle, "filename") failed for whatever reason.

              2) I switched to use PHP to implement to same function a couple of days
              ago. Then you know all about it now.

              3) If I use command line to execute the perl code,
              perl perlcode.pl
              the code can correctly write the output file: 'filename'

              4) The server doesn't allow me to run the PHP executable from the
              command line, so I can provide other details any more.

              thanks,

              Comment

              • News Me

                #8
                Re: permission denied - fopen

                bird wrote:[color=blue]
                > bird wrote:
                >[color=green]
                >> Jeb Hunter wrote:
                >>[color=darkred]
                >>> who owns the folder?
                >>>[/color]
                >> The folder modes is as below:
                >> ----------------------------------
                >> drwxrwxrwx 9 kmei student 4096 Feb 18 22:31 www
                >> ----------------------------------
                >> The parent of 'www' is my home on the server. please see the path:
                >> /home/lookout/u2/kmei/www/test1.php
                >> 'kmei' is my ID on the server.[/color][/color]
                [snip][color=blue]
                > 3) If I use command line to execute the perl code,
                > perl perlcode.pl
                > the code can correctly write the output file: 'filename'[/color]

                When the webserver (apache..?) executes the script (perl or php), it's
                not running as kmei:student, it's probably running as apache:apache or
                whatever user:group the server administrator has configured apache to
                run as. Whatever user:group apache runs as needs to have read-execute
                privilege through all dirs in the path up to www, where it also needs
                write privilege; it needs read-write privilege on test1.php.

                NM

                --
                convert UPPERCASE NUMBER to a numeral to reply

                Comment

                • bird

                  #9
                  Re: permission denied - fopen

                  News Me wrote:[color=blue]
                  > bird wrote:
                  >[color=green]
                  >> bird wrote:
                  >>[color=darkred]
                  >>> Jeb Hunter wrote:
                  >>>
                  >>>> who owns the folder?
                  >>>>
                  >>> The folder modes is as below:
                  >>> ----------------------------------
                  >>> drwxrwxrwx 9 kmei student 4096 Feb 18 22:31 www
                  >>> ----------------------------------
                  >>> The parent of 'www' is my home on the server. please see the path:
                  >>> /home/lookout/u2/kmei/www/test1.php
                  >>> 'kmei' is my ID on the server.[/color][/color]
                  >
                  > [snip]
                  >[color=green]
                  >> 3) If I use command line to execute the perl code,
                  >> perl perlcode.pl
                  >> the code can correctly write the output file: 'filename'[/color]
                  >
                  >
                  > When the webserver (apache..?) executes the script (perl or php), it's
                  > not running as kmei:student, it's probably running as apache:apache or
                  > whatever user:group the server administrator has configured apache to
                  > run as. Whatever user:group apache runs as needs to have read-execute
                  > privilege through all dirs in the path up to www, where it also needs
                  > write privilege; it needs read-write privilege on test1.php.
                  >
                  > NM
                  >[/color]
                  Yes, I think I understand your point. I knew it's different to run the
                  PHP/perl code by a command line or by a web browser. That's why I didn't
                  mention the above 3) case when I first asked for help. I actually set
                  the mode of every related file and folder to 777, since I have been
                  trying hard to find the "bug". By saying that I mean the mode of the two
                  files 'test1.php' and 'filename' were set to 777, and so was the folder
                  'www'. Thus, 'all users' including 'apache' and 'nobody' should have the
                  read-write-execute privilege to all the related files.

                  I wonder if the administrator has done something special to the system,
                  or it's a bug in the system, or whatever beyond my knowledge. I am just
                  curious to learn it. (Note that I've already achieved my goal to
                  implement the same function by PHP+MySQL on the university server; I
                  write data to MySQL database instead of a local file.)

                  Thank you very much,
                  Kevin

                  Comment

                  • News Me

                    #10
                    Re: permission denied - fopen

                    bird wrote:

                    [big snip]
                    [color=blue]
                    > I wonder if the administrator has done something special to the system,
                    > or it's a bug in the system, or whatever beyond my knowledge. I am just
                    > curious to learn it. (Note that I've already achieved my goal to
                    > implement the same function by PHP+MySQL on the university server; I
                    > write data to MySQL database instead of a local file.)[/color]

                    I doubt it's a bug. As a security measure the admin may have restricted
                    PHP and/or Apache to only be allowed to write files in a specific
                    branch of the filesystem.

                    NM

                    --
                    convert UPPERCASE NUMBER to a numeral to reply

                    Comment

                    Working...