Connecting Tech Pros Worldwide Forums | Help | Site Map

cannot unlink file that Apache and I have permissions to delete

Phil Powell
Guest
 
Posts: n/a
#1: Jul 17 '05
[PHP]
print_r(is_file("$logPath/$logFileName")); // RETURNS 1
unlink("$logPath/$logFileName"); // RETURNS WARNING: PERMISSION DENIED
[/PHP]

This code should tell me that the file located at
$logPath/$logFileName should delete the log file, however, it never
deletes it due to permissions error.

However, upon checking the file properties I find this:
  • I am a member of the group with full permissions to edit/write/delete
    the file
    Apache is a member of the same group with full permissions to
    edit/write/delete the file
    Apache and I are in the group that has full permissions to
    edit/write/delete all other files in the exact same folder and those
    can ALL be edited, written or deleted

This file was created and transferred the same way as all others, is a
text file and contains only text, no binary characters of any kind.
However, it can never be deleted even though I have permissions to do
so as does Apache.

What could I be doing wrong?

Thanx
Phil

Pjotr Wedersteers
Guest
 
Posts: n/a
#2: Jul 17 '05

re: cannot unlink file that Apache and I have permissions to delete


Phil Powell wrote:[color=blue]
> [PHP]
> print_r(is_file("$logPath/$logFileName")); // RETURNS 1
> unlink("$logPath/$logFileName"); // RETURNS WARNING: PERMISSION DENIED
> [/PHP]
>
> This code should tell me that the file located at
> $logPath/$logFileName should delete the log file, however, it never
> deletes it due to permissions error.
>
> However, upon checking the file properties I find this:
>
>
  • > I am a member of the group with full permissions to edit/write/delete
    > the file
    > Apache is a member of the same group with full permissions to
    > edit/write/delete the file
    > Apache and I are in the group that has full permissions to
    > edit/write/delete all other files in the exact same folder and those
    > can ALL be edited, written or deleted
    >
>
> This file was created and transferred the same way as all others, is a
> text file and contains only text, no binary characters of any kind.
> However, it can never be deleted even though I have permissions to do
> so as does Apache.
>
> What could I be doing wrong?
>
> Thanx
> Phil[/color]

I don't know all that much about (linux?) file permissions, but my first
thought was: is the file perhaps locked by another process/owner at the time
of attempted deletion ?

HTH
Pjotr


Andy Hassall
Guest
 
Posts: n/a
#3: Jul 17 '05

re: cannot unlink file that Apache and I have permissions to delete


On Wed, 28 Jul 2004 19:43:43 +0200, "Pjotr Wedersteers" <x33159@westerterp.com>
wrote:
[color=blue]
>I don't know all that much about (linux?) file permissions, but my first
>thought was: is the file perhaps locked by another process/owner at the time
>of attempted deletion ?[/color]

Typically this just results in the file disappearing from the visible
filesystem, but the file still staying allocated and accessible by the
process(es) that have it open until they all release the file, at which point
the inode gets cleared up and the space released.

--
Andy Hassall <andy@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Luciano Tolomei
Guest
 
Posts: n/a
#4: Jul 17 '05

re: cannot unlink file that Apache and I have permissions to delete


>
  • [color=blue]
    > I am a member of the group with full permissions to edit/write/delete
    > the file
    > Apache is a member of the same group with full permissions to
    > edit/write/delete the file
    > Apache and I are in the group that has full permissions to
    > edit/write/delete all other files in the exact same folder and those
    > can ALL be edited, written or deleted
    >
[/color]

it is not important your permissions or your gruop.
only apache is important.

have you checked if the file is writable by the group ?
if the file is yours of your gruop but only you can write it apache can
do nothing.
Gordon Burditt
Guest
 
Posts: n/a
#5: Jul 17 '05

re: cannot unlink file that Apache and I have permissions to delete


>[PHP][color=blue]
>print_r(is_file("$logPath/$logFileName")); // RETURNS 1
>unlink("$logPath/$logFileName"); // RETURNS WARNING: PERMISSION DENIED
>[/PHP]
>
>This code should tell me that the file located at
>$logPath/$logFileName should delete the log file, however, it never
>deletes it due to permissions error.
>
>However, upon checking the file properties I find this:
>
>
  • >I am a member of the group with full permissions to edit/write/delete
    >the file
    >Apache is a member of the same group with full permissions to
    >edit/write/delete the file
    >Apache and I are in the group that has full permissions to
    >edit/write/delete all other files in the exact same folder and those
    >can ALL be edited, written or deleted
    >
[/color]

Show me the permissions and ownerships, on both the file and the
directory it's in. Also, what user/group does Apache run as?

What OS has an "edit" permission on files? If this is a UNIX-like
OS, is it on a read-only filesystem? Does it have the immutable
bit set? Does it have the system or user-level undeletable bit
set? What type of object is it? (You can't unlink() a directory).

Is it possible that this is a *PHP* "permission denied", not an *OS*
"permission denied"? Is safe mode on?

[color=blue]
>This file was created and transferred the same way as all others, is a
>text file and contains only text, no binary characters of any kind.
>However, it can never be deleted even though I have permissions to do
>so as does Apache.[/color]

Gordon L. Burditt
Average_Joe
Guest
 
Posts: n/a
#6: Jul 17 '05

re: cannot unlink file that Apache and I have permissions to delete


In article <1cdca2a7.0407280914.1ae586e@posting.google.com> , Phil Powell wrote:[color=blue]
> [PHP]
> print_r(is_file("$logPath/$logFileName")); // RETURNS 1
> unlink("$logPath/$logFileName"); // RETURNS WARNING: PERMISSION DENIED
> [/PHP]
>
> This code should tell me that the file located at
> $logPath/$logFileName should delete the log file, however, it never
> deletes it due to permissions error.
>
> However, upon checking the file properties I find this:
>
> This file was created and transferred the same way as all others, is a
> text file and contains only text, no binary characters of any kind.
> However, it can never be deleted even though I have permissions to do
> so as does Apache.
>
> What could I be doing wrong?[/color]

Are you able to delete it using the shell and/or FTP?

I'm assuming UNIX. (Because I can't help much with windows..)

My first guess is that Apache is "running as" another user. Assuming
you've already tried it..

Is it possible the directory was chmod'd?

Is Apache serving content from a directory mounted via NFS? (If so,
could the filesystem have been mounted read only?)

One thing to check is if Apache is able to create files in the same
directory. If so, then you can be reasonably sure the problem is with
the file itself.

If Apache can create files in the same directory, do a compare on file
ownerships.

Another thing to check, if you've got shell access are any extended
attributes. lsattr might do the trick if it's an ext* file system. I've
spent a few hours puzzling over that one before. :-) chattr is a handy
way to keep your "kid sister" or root from accidently zapping critical
files. Sometimes log files are set with an "append only" attribute.

Jamie
--
http://www.geniegate.com Custom web programming
User Management Solutions Perl / PHP / Java / UNIX

Closed Thread


Similar PHP bytes