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.

link|improve this question
<?php echo getmyuid() . ' - ' . getmygid(); ?> 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 – DavidLiu Oct 15 '10 at 16:51
500 - 500, it's weird. Do you know what it suppose to mean? – DavidLiu 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? – DavidLiu Oct 15 '10 at 17:12
show 2 more comments
feedback

3 Answers

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

link|improve this answer
feedback

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.

link|improve this answer
I'm using Cent OS, and SELinux status is disabled. – DavidLiu Oct 16 '10 at 6:48
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.