0

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;
}
  • Check the answer here: http://stackoverflow.com/questions/23372897/undefined-reference-to-collect2-ld-returned-1-exit-status – Chella Oct 29 '14 at 05:48

1 Answers1

1

This actually happens because not having permission to create .out file. May be when you compile or run it through terminal you will have enough permissions to do so and you might have run from the folder where the c file resided. Please check through the permission. Do remember that when you run a php file the user is www-data not root or any other.

Chella
  • 1,561
  • 4
  • 23
  • 42