I am working on a small php-mysql project and working inside /var/www/project on a freshly installed Apache/2.2.22 server(Ubuntu) in Ubuntu 12.04.1
I have chown[ed] the /var/www folder recursively to give ownership to www-data. Inside project i have a php file that tries to execute exec('gcc sample.c') but i get an error saying collect2: ld returned 1 exit status.I do not get this error when doing this through terminal.
In addition, an executable a.out placed inside the same folder runs fine when exec('gcc sample.c') is replaced by exec('./a.out')
How can i fix this? PS:I am a total beginner in this.
php code inside project:
<?php
require('connect.php');
$path='sample.c';
chmod($path,0777);
$command= 'gcc sample.c 2>&1';
$method = exec($command);
print_r($method);
?>
sample.c code:
#include<stdio.h>
int main()
{
printf("SUCCESS\n");
return 0;
}