I think it actually still might be a permissions issue. I tested your program using this script:
PHP Code:
<?php
$command = "gcc ". $com ." >& err.out";
echo $command;
system($command);
?>
then inserted a nice ?com=hello.c to try and test it. Well you are right. It will write out and create a file named err.out after gcc is done. Why? Because while it does have permission to run gcc, you do not have permission as user www-data (or nobody) to create a file inside of the directory. How did I get around this? 2 ways. First try and creating a file named err.out and changing its permissions to 755. Or if that doesnt suit you too well try creating a direcotry and changing the permissions on this directory to 755. Then stick the error file in there like:
mkdir nobody
chmod 755 nobody
PHP Code:
<?php
$command = "gcc ". $com ." >& nobody/err.out";
echo $command;
system($command);
?>
I hope that helps.