相同点:
1.在安装目录apache下找到文件httpd.conf,检查以下代码是否前面有#,如果有就去掉
LoadModule cgi_module modules/mod_cgi.so
2.查看并修改一下代码中的路径,与下面的第4点中的路径一致
ScriptAlias /cgi-bin/ "D:/SoftWare/XAMPP/cgi-bin/"
AddHandler cgi-script .cgi .pl .asp .py .exe
4.找到类似下面的代码块(里面的路径改为自己的安装路径,我这里是一个集成环境)
#
# "D:/SoftWare/XAMPP/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "D:/SoftWare/XAMPP/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
apache2.4修改为:
<Directory "D:/SoftWare/XAMPP/cgi-bin">
AllowOverride None
Options Indexes FollowSymLinks ExecCGI
Require all granted
Require host ip
</Directory>
在apache2.2中则改为
<Directory "D:/SoftWare/XAMPP/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
5.举一个python的例子,创建文件hello.py,文件内容如下:
注意:注释中的路径一定要改好
#!D:\SoftWare\python3.6\python.exe #linux一般为#!usr/bin/python
# -*- coding: utf-8 -*-
print "Content-type:text/html"
print # 空行,告诉服务器结束头部
print '<html>'
print '<head>'
print '<meta charset="utf-8">'
print '<title>Hello Word!</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word!</h2>'
print '</body>'
print '</html>'
将该文件放到cgi-bin目录下,
浏览器输入localhost/cgi-bin/hello.py
结果: