I am building online compiler for C and C++ using php, so we are using gcc compiler
to execute using "shell_exec" function ,
test.php
<?php
$output = shell_exec("gcc /var/www/test/main.c 2>&1");
print_R($output);
?>
If I execute in terminal like php test.php
, is working fine and it is creating a.out
compiled file.
But If I try to run in the browser like localhost/test.php
, its giving below error
gcc: error trying to exec 'cc1': execvp: No such file or directory
I gave full permission (0777) to test.php
,
$ whereis cc1 // cc1:
Please find below version I am using
gcc version 5.4.0
PHP 7.0.32
OS: ubuntu 16.04
server : Nginx
Is there any alternate to run C and C++ using PHP or how to resolve this issue whille running from the browser.