在Apache服务器中运行CGI程序的方法
程序员文章站
2023-08-21 20:49:34
关于apache与cgi在这里就不解释了.
1、apache下载地址:http://www.apache.org,下面以2.0.63为例介绍运行cgi程序的配置。
2、...
关于apache与cgi在这里就不解释了.
1、apache下载地址:http://www.apache.org,下面以2.0.63为例介绍运行cgi程序的配置。
2、下载windows下的perl解释器activeperl,官方网站:http://www.activestate.com/,最新版本activeperl- 5.10.0.1003,假设安装路径为c:\perl。
3、修改apache的配置文件httpd.conf:
<directory "d:/apache group/apache2/cgi-bin"> allowoverride none options none order allow,deny allow from all </directory> #addhandler cgi-script .cgi
改为:
<directory "d:/apache group/apache2/cgi-bin"> allowoverride none options execcgi order allow,deny allow from all </directory> addhandler cgi-script .cgi .pl
4、编写perl脚本程序hello.pl
#!c:\perl\bin\perl.exe print "content-type: text/html","\n\n"; print "<html>","\n"; print "<head>","\n"; print "<title>perl</title>","\n"; print "</head>","\n"; print "<body>","\n"; print "<h1>hello world</h1>","\n"; print "</body>","\n"; print "</html>","\n";
将程序拷贝到apache安装目录下cgi-bin文件夹下.
5、启动apache服务器,打开浏览器,输入http://localhost/cgi-bin/hello.pl
结果如下: