日期:2014-05-16  浏览次数:20682 次

Win7(64位) 安装Apache | 测试CGI

Win7(64位) 安装Apache | 测试CGI

Blackdot.be

下载 httpd-2.2.xx-win64.rar,Apache 64-bit 的压缩包

(Apache官方没有64位的安装包)

将压缩包解压到C盘根目录

以管理员身份运行CMD,进入 C:\httpd-2.2-x64\bin

输入:httpd -k install

提示:The Apache2.2 service is successfully installed. 安装成功

接着是错误提示,是Testing httpd.conf....的错误,要配置httpd.conf就可以了

现在用记事本打开conf目录下的httpd.conf

搜索ServerRoot,把后面的目录改为当前目录,即"/httpd-2.2-x64"

搜索DocumentRoot,把后面的目录改为自己的网页的目录

搜索DirectoryIndex,在后面添加默认主页名字index.html index.htm index.php

搜索ServerName,去掉#号,把后面的网址改成自己的,如: 127.0.0.1:80

在httpd.conf末尾添加如下代码:yourpath你的网站目录

<Directory "d:/yourpath/">

?

Allow from all

</Directory>

?

注意:如果电脑安装了IIS的话,要和Apache监听的端口要不同,不然Apache启动不了

?

使用Apache,在CMD下,进入\httpd-2.2-x64\bin目录,输入以下命令:

启动Apache:httpd -k start

重启Apache:httpd -k restart

关闭Apache:httpd -k shutdown

?

测试Apache:

把自己的网页弄好后,放在工作目录

打开浏览器,输入:127.0.0.1能打开网页,就完成了




运行Perl写的CGI

安装Active Perl,提供Perl运行环境

修改Apache的配置:

打开httpd.conf文件

1.搜索cgi-bin

找到 ScriptAlias /cgi-bin/ "/Apache/cgi-bin/

删除前面的#号,修改存放cgi文件的路径

2. 搜索AddHandler

找到AddHandler cgi-script .cgi

这是定义可执行cgi文件扩展名,加上Perl的扩展名,改成AddHandler cgi-script .pl ,.cgi


3.搜索CGI directory

更改Options、Allow Override的参数为All

# CGI directory exists, if you have that configured.

#

<Directory "/apache/cgi-bin">

AllowOverride all

Options all

Order allow,deny

Allow from all

</Directory>


4.建立文件 test.pl , 内容如下:

#!/Perl/bin/perl.exe

##(上面这个是Perl.exe的路径)

##如果没有第一行或写错,apache找不到perl解释器

##会出现500 Internal Server

print "Content-type:text/html\n\n";

print "CGI执行测试"


5. 建立一个html文件:

<html>

<body>

<a href="http://127.0.0.1/cgi-bin/test.pl" >CGI测试</a>

</body>

</html>

重新启动apache,然后在浏览器打开这个文件