0

There is a file(644, owner:apache) that I can't delete it using a PHP script with unlink function.

I can't figure it out why unlink fails to delete this file.

BTW, I have tried fclose it before unlink it. Unfortunately, it still didn't work.

“drwxrwxrwx 2 apache apache” apache have write access to the directory.

David Liu
  • 313
  • 1
  • 3
  • 6
  • `` what is the output ? I am guessing youre running your httpd server with antoher user that does not have access to the file. – Guapo Oct 15 '10 at 16:42
  • it returns 500 - 500 – David Liu Oct 15 '10 at 16:51
  • 500 - 500, it's weird. Do you know what it suppose to mean? – David Liu Oct 15 '10 at 16:52
  • that is sort of weird because considering the chmod 644 which allows others to erase the file it should work fine even from the httpd server, can you update with the unlink error ? 500 is the user id and group you can type `cat /etc/passwd |grep 500` on the console to check what username is it. – Guapo Oct 15 '10 at 16:55
  • I am using the unlink function in PHP. According to the official document. This function "Returns TRUE on success or FALSE on failure". So I don't know the specific error, is there a way to find it out? – David Liu Oct 15 '10 at 17:12
  • “drwxrwxrwx 2 apache apache” apache have write access to the directory. – David Liu Oct 16 '10 at 06:12
  • When you find the solution by yourself (as I think it is a problem due to either your code, or something you didn't tell us), please update your question to tell the answer, even if it may make you look like a bit dumb :-) – Déjà vu Oct 16 '10 at 07:17

3 Answers3

2

Does apache have write access to the directory that the file is in ?

user9517
  • 114,104
  • 20
  • 206
  • 289
0

What server operating system are you using? It's possibly SELinux causing this - if you have an OS with that installed, look in /var/log/secure or maybe /var/log/audit/audit.log for mentions of the file you are trying to unlink.

TessellatingHeckler
  • 5,676
  • 3
  • 25
  • 44
0

Sorry, guys. Problem solved.

It turns out the other mistake in my script have caused the problem. But I still learned a lot in this discussion. Thanks.

David Liu
  • 313
  • 1
  • 3
  • 6