Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|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

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

share|improve this answer

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.

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

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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