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

I have the problem that when I try to copy some files from php I get the response that it failed, but the file is actually copied. This is a problem since I log an error message and exit the script when it fails but there are still plenty left for the script to do.

I've tried two different ways of copy:

if(!copy("/var/www/html/", "/etc/conf/".$new_dir."/"))

if(shell_exec("cp $src $dest")==null)

I have labeled 'conf' in order for SELinux to allow apache to write to it:

chcon -R -t httpd_sys_script_rw_t /etc/conf

Does anyone have any clue why this can happen and how to fix it?

share|improve this question
What exactly response do you get? – Vladislav Rastrusny May 16 '12 at 13:35

and the answer:

shell_exec will return a string, the output of this program. If it return some "blablabla" and you compares to null it will be false.

use the function exec

and compare the return_var with zero -- if success it will be equal to zero, other value in case of failure.

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.