直接上干货.
一.下载
进入apache的官网:Welcome! - The Apache HTTP Server Project,
1.点击左边的download。
2.点击链接 a number of third party vendors
3.点击链接 AphacheHaus
4.这边可以看到很多版本根据自己需要选择,这边注意的是点击箭头指的这个小房子一样的AH进行下载
5.解压
6.进入下面文件修改路径和参数(注意标记的路径)
这边是我使用的路径
修改端口号,默认为80端口号,易被其他占用这边我改为8078(两个地方端口号都同步修改)
7.安装
这边注意:一定要以管理员权限进入Aphche24下的bin目录
执行命令httpd -k install 因为这边我已经安装过了 界面反馈的不一样
正常的显示的应该是:
Installing the Apache2.4 service
service is successfully installed.
Testing httpd.conf...
Errors reported here must be corrected before the service can be started.
8.安装好以后启动点击以下文件运行
9.检验是否安装:输入http://localhost:8078/,出现以下界面就是安装好了。
10.接下来写一个test文件来验证一下
在\Apache24\cgi-bin目录下创建一个test.py文件进行测试.
文件内容注意!!这边路径必须是你自己的python执行文件的路径
如果你不知道自己路径是多少,打开命令行输入py -0p 回车会显示路径直接复制过去就行
注意(这边的0不是欧o,是零0)
最后再运行一下localhost:8078/cgi-bin/test.py 出现以下页面就是成功了
#!C:\Users\zhujunnan\AppData\Local\Programs\Python\Python39\python.exe
# -*- coding: UTF-8 -*-
print("Content-type:text/html;charset=GBK")
# 空行,告诉服务器结束头部,没有会报错
print()
print('<html>')
print('<head>')
print('<meta charset="utf-8">')
print('<title>Hello CGI program </title>')
print('</head>')
print('<body>')
print('<h2>Hello,This is a CGI test program for windows</h2>')
print('</body>')
print('</html>')