CGI - Common Gateway Interface

Pre-Condition:

Install Apache2, setup system path, register httpd as a service:

httpd -k install

The CGIHTTPServer module has been MERGED into http.server in Python 3

CGI - Common Gateway Interface_第1张图片
httpd usage;

Running a Simple CGI Web Server with python3 on windows via Apache2

1. Update httpd.conf , define SRVROOT to the apache2 home path, make sure cgi_module loaded, and uncommit 'AddHandler' after adding '.py' to it;

#

# ServerRoot: The top of the directory tree under which the server's

#

Define SRVROOT "G:\Apache24"

ServerRoot "${SRVROOT}"

AddHandler cgi-script .cgi .pl .py

LoadModule cgi_module modules/mod_cgi.so

2). restart Apache2 service;

3). put 'hello.py' script under path '%SRVROOT%/cgi-bin/', the script content:

CGI - Common Gateway Interface_第2张图片
sample;

4). open 'http://localhost/cgi-bin/hello.py' with browser, it works!

CGI - Common Gateway Interface_第3张图片

你可能感兴趣的:(CGI - Common Gateway Interface)