安装可以百度,一搜一大堆,主要介绍cgi执行C++和python的注意事项;
前期踩过很多坑,改了好多次配置,希望我的坑别人不要再踩!!!!!!
1.首先httpd.conf文件的修改,只需要需改以下的几个地方:
这里是Apache2.4安装的绝对路径:
端口的设置:
这里修改一下:
这里很重要:
2.HTML的运行:
将htm文件放在 Apache24\htdocs 目录下,在浏览器直接访问:
3.c++的执行:
#include <iostream>
using namespace std;
int main ()
{
cout << "Content-type:text/html\r\n\r\n";
cout << "<html>\n";
cout << "<head>\n";
cout << "<title>Hello World - 第一个 CGI 程序</title>\n";
cout << "</head>\n";
cout << "<body>\n";
cout << "<h2>Hello World! 这是我的第一个 CGI 程序</h2>\n";
cout << "</body>\n";
cout << "</html>\n";
return 0;
}
cout << "Content-type:text/html\r\n\r\n"; 这一句表明html的Content type为text格式;
写好测试代码,找个编译器编译通过,生成.exe文件,将文件cope到cgi-bin目录下;在浏览器中运行:
4.python的执行:
python代码如下:
#!D:\python\software\python.exe
print ("Content-type:text/html")
print () # 空行,告诉服务器结束头部
print ('<html>')
print ('<head>')
print ('<title>Hello Word - 我的第一个 CGI 程序!</title>')
print ('</head>')
print ('<body>')
print ('<h2>Hello Word! 我是来自菜鸟教程的第一CGI程序</h2>')
print ('</body>')
print ('</html>')
#!D:\python\software\python.exe 这一句很重要,它是python的安装路径,路径如果写的不对会报如下错误: