ponh 发表于 2015-8-4 10:18:30

perl--CGI编程之Apache服务器安装配置

  使用perl进行CGI开发必须安装WEB服务器,一般用Apache比较好,因为它可跨平台,并且可以经perl、python等模块编译其中,速度更快,下面就简单介绍一下Apache在windows下的安装和配置:
  (1)安装Apache
  在windows下下载Apache的安装包,直接安装即可,例如本人将Apache安装在D:\Program Files\Apache2.2中,cgi_bin目录为 D:\Program Files\Apache2.2\cgi-bin;perl.exe目录为d:/perl/bin
  (2)配置Apache
  在开始菜单中用文本编辑器打开Apache的配置文件httpd.conf文件,

   1.搜索cgi-bin,找到ScriptAlias /cgi-bin/ "D:/Program Files/Apache2.2/cgi-bin/",如果前面有#号,则删除(windows中默认没有#号),这是存放cgi文件的路径
   2. 搜索AddHandler找到AddHandlercgi-script .cgi ,这是定义可执行cgi文件扩展名,可以把.cgi 改为 .pl 或加上”, .pl” ,成为“AddHandler cgi-script .pl ,.cgi“这样两个后缀都可以用了。
3.修改cgi端口
   默认为80端口,可修改为其他端口。方法是找到Listen项,Listen80那一行,后面的80改为一个不常用的端口,如1087
   
4.更改Options、Allow Override的参数为All。
      改完之后象这样:
      #

      # "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin" should be changed to whatever your ScriptAliased
      # CGI directory exists, if you have that configured.
      #
      
          AllowOverride all
          Options all
          Order allow,deny
          Allow from all
      
5.测试

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

      #!d:/Perl/bin/perl   
      ##   写成!d:/Perl/bin/perl.exe也可以
      ## 注意,如果没有第一行或写错,apache找不到perl解释器
      ## ,会出现500 Internal Server   
      print "Content-type:text/html\n\n";
      print "CGI执行成功!"
      将此文件放入D:\Program Files\Apache2.2\cgi-bin中

      在任意位置建立一个html文件,内容如下:

       CGI
      IE截图:
          如果没有错误的话,至此配置成功!
页: [1]
查看完整版本: perl--CGI编程之Apache服务器安装配置