'From HTTP1.1 to HTTP2 - getting error -gcc: fatal error: cannot execute 'cc1': execvp: No such file or directory

I am trying to run the following PHP code on ubuntu20.04 on Apache2 server:

<?php 
  exec("gcc /path/main.c -o /path/main.out 2> /path/compile-error.txt");
  $compile_error = file_get_contents("/path/compile-error.txt");
  echo "<pre>$compile_error</pre>";
  $output = exec('/path/main.out');
  echo "<pre>$output</pre>";
?>

The main.c file contains the following code:

#include <stdio.h>   
int main() { 
  printf("Hello, World!");    
  return 0; 
}

The code was running fine and was displaying “Hello World!”.

Then I enabled HTTP2 (all steps followed as shown below – disabling mpm_prefork and enabling mpm_event).

sudo apt-get install php8.1-fpm
sudo a2dismod php8.1 
sudo a2enconf php8.1-fpm
sudo service apache2 restart
sudo a2dismod mpm_prefork
sudo a2enmod mpm_event
sudo service apache2 restart && sudo service php8.1-fpm restart
sudo nano /etc/apache2/apache2.conf and added Protocols h2 h2c http/1.1
sudo a2enmod http2
sudo a2enmod mpm_event proxy_fcgi setenvif
sudo apachectl configtest && sudo service apache2 restart

The HTTP2 is running fine. But the above-mentioned code gives the following error:

gcc: fatal error: cannot execute 'cc1': execvp: No such file or directory
compilation terminated.

Please note that I am still able to run the command on shell successfully but not through http. I have tried the following steps to resolve it but it was not successful:

  • Reinstalled gcc
  • Reinstalled build-essential


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source