Ubuntu18.04 apache2 configure CGI (and test: hello.c)

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
Insert picture description here
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
Insert picture description here
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
Insert picture description here
third step, enter conf-enabled, and open the serve-cgi-bin.conf to add the same as the modified figure. The
Insert picture description here
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

Insert picture description here
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;
}

Insert picture description here
Enter the following command

sudo gcc -o hello.cgi hello.c

Insert picture description here
The sixth step, enter localhost/cgi-bin/hello.cgi in the browser, and the following effects can be successfully displayed. If you
Insert picture description here
are interested, you can test other types of scripts. This article only uses the .c file as an example

Guess you like

Origin blog.csdn.net/weixin_44925547/article/details/106244371
Recommended