First, find the directory/usr/local/apache2/conf to install Apache, and modify the httpd.conf configuration file.
1. Loading the CGI module
Remove Comments:
LoadModule cgid_module modules
/mod_cgid
.so #//当使用内置模块prefork.c 时动态加载cgi_module
LoadModule cgi_module modules/mod_cgi.so #当使用内置模块worker. C Dynamic Load Cgid_module
2. Set the CGI script file path
ScriptAlias
/cgi-bin/
"
/var/www/cgi-bin/"
3. Set access permissions for CGI paths
<directory"/var/www/cgi-bin"> allowoverride None Options +execcgi Order Allow, Deny allow from all </Directory>
4. Set Apache to interpret Python's CGI script file
AddHandler cgi-script. cgi. py
Once these are configured, restart the Apaache.
Second, add CGI script file
Under the/var/www/cgi-bin/directory, create the hello.py file, add the following code, and copy the permissions to chmod 755 hello.py.
#!/usr/bin/env python#-*-coding:utf-8-*- Print "content-type:text/html"PrintPrint ''Print ''Print '<title>Hello</title>'Print ''Print '<body>'Print ''Print '</body>'Print ''
Three-step, browser-accessible
localhost/cgi-bin/hello.py
Reference Document: http://xpleaf.blog.51cto.com/9315560/1740221
Http://www.runoob.com/python/python-cgi.html
CGI configuration for Linux Python Apache