CGI-Script in C. Apache http 500 server error output

Friends, good afternoon.I downloaded the server Apache 2.1 to my local computer (linux Ubuntu 18.04).The server works without problems (syntax ok). There was such a problem .For testing, I created a script in the C language. The script added to the folder /usr/lib/cgi-bin/ as written in the server settings. But when entering localhost/cgi-bin/script.cgi http 500 server error is output . You can tell me what the problem is .I will say that the creak compiled on the GNU compiler.Thank you in advance

Here is CGI-script on C

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main (void) {
int num;
time_t t;
srand (time ( &t) ) ;

num = rand() % 10;

printf ("Content-type: text/html \n");
printf("Pragma: no-cache\n");
printf ( "\n");
printf("<!DOCTYPE  html>");
printf("<html lang='en'>");
printf("<head>");
printf("<title>Look This Amazing</title>");
printf("<meta charset='utf-8'>");
printf("</head>");
printf("<body>");
printf("<h1>Look This Amazing!</h1>");
printf("</body>");
printf("</html>");

}
Author: Rivera Time Club, 2018-08-25

1 answers

Friends the code worked .The problem was incorrect compilation. Several repositories were not loaded build-essential. Algorithm of actions for correct operation CGI.

Creating a file script.c in the folder gci-bin (root@root:/usr/lib/cgi-bin$ sudo touch script.c ).

Opening the file script.c (root@root:/usr/lib/cgi-bin$ sudo nano script.c).

Adding CGI scripts

#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main (void) {
int num;
time_t t;
srand (time ( &t) ) ;

num = rand() % 10;

printf ("Content-type: text/html \n");
printf("Pragma: no-cache\n");
printf ( "\n");
printf("<!DOCTYPE  html>");
printf("<html lang='en'>");
printf("<head>");
printf("<title>Look This Amazing</title>");
printf("<meta charset='utf-8'>");
printf("</head>");
printf("<body>");
printf("<h1>Look This Amazing!</h1>");
printf("</body>");
printf("</html>");

}

Save Ctrl+s . Ctrl+x

Let's compile script.c on gnu compiler

 root@root:/usr/lib/cgi-bin$ sudo gcc /usr/lib/cgi-bin/script.c -o script.cgi

The compliment is complete cgi the creak is ready.

Enter in url localhost/cgi-bin/script.cgi we will see our desired siat

Who neb'ud will help

 0
Author: Rivera Time Club, 2018-08-26 10:12:26