1. Install apache2
sudo apt update
sudo apt install apache2
2.
The directory for configuring all configuration files of cgi apache2 is in /etc/apache2/, enter this directory for related configuration. The
first step is to enter sites-enabled and edit 000-default.conf, and change it as shown below. Note that there are deletions in the
figure above Comment on the bottom line, remember to delete
The second step is to enter the mods-enabled directory, open the mime.load file, and add the module. The
third step, enter conf-enabled, and open the serve-cgi-bin.conf to add the same as the modified figure. The
fourth step, restart the apache server
sudo /etc/init.d/apache2 restart
The fifth step is to create a new cgi-bin folder in the /var/www/ directory, and then create a new hello.c in cgi-bin
sudo mkdir cgi-bin
Add the following code in hello.c
#include <stdio.h>
int main()
{
printf("Content-Type: text/html\n\n");
printf("Hello, world\n");
return 0;
}
Enter the following command
sudo gcc -o hello.cgi hello.c
The sixth step, enter localhost/cgi-bin/hello.cgi in the browser, and the following effects can be successfully displayed. If you
are interested, you can test other types of scripts. This article only uses the .c file as an example