fateame 发表于 2017-1-6 07:14:20

Perl_Apache_CGI_安装_windows_win7_vista

  为了回家工作和学习perl,不得不在laptop上装一个windows的perl环境。
  Google一下,安装步骤和注意事项。另外还是主要看看cpan上的介绍比较官方。
  还是那句老话,按照这里的流程,但不要拘泥于这里,因为大家的知识背景和软件环境不一定相同,请随机应变吧~
  1. 安装Apache ( http://httpd.apache.org) )和 ActiveState Perl (http://www.activestate.com/ )。
  如果去cpan上看,还是可以到这里的。同时可以看到,除了ActiveState的perl外,还有一个开源的环境,应该也是可以用的。

  
2. 安装mod_perl。
ppm install http://theoryx5.uwinnipeg.ca/ppmpackages/mod_perl.ppd安装完毕之后会提示输入Apache的路径,输入类似于 D:/Apache2/modules。
      注意:可以先到这里看看详情http://theoryx5.uwinnipeg.ca/ppmpackages,看到提示你安装跟自己的perl版本一致的版本,我的版本是(命令perl -v) 得到v5.12.2,所以应该用如下命令安装:
  C:\setup\perl\bin>ppm install http://cpan.uwinnipeg.ca/PPMPackages/12xx/mod_perl.ppd

  详情看这里:http://cpan.uwinnipeg.ca/PPMPackages/
  另外:我碰到如下提示,所以就先安装gcc编译器吧。
  It looks like you don't have a C compiler on your PATH, so you will not be
able to compile C or XS extension modules.  You can install GCC from the
MinGW package using the Perl Package Manager by running:                               
    ppm install MinGW                                                                                  

 
  安装完毕后显示: 
Fetching http://cpan.uwinnipeg.ca/PPMPackages/12xx/x86/mod_perl.so ...  done!
Where should mod_perl.so be placed? C:\setup\Apache2.2\modules
mod_perl.so has been successfully installed to C:/setup/Apache2.2/modules.
To enable mod_perl, put in the directives
   LoadFile "C:/Path/to/Perl/bin/perl510.dll"
   LoadModule perl_module modules/mod_perl.so
in httpd.conf. For more information, visit
   http://perl.apache.org/
and especially see
   http://perl.apache.org/docs/2.0/rename.html
  
3. 配置mod_perl。修改httpd.conf。
  增加以下几行:
  LoadFile "c:/setup/perl/bin/perl512.dll"
LoadModule perl_module modules/mod_perl.so
  如果安装的httpd自带ssh,则不需要手动配置添加如下行:
  <IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
  修改:
  在Apache的安装目录下找到conf/httpd.conf文件,用记事本或其他的文本编辑器打开。
  查找“ScriptAlias /cgi-bin/”,可能你的会是下面的这个结果:
  ScriptAlias /cgi-bin/ “C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/”
  如果这行前面的有个“#”符号,就将它去掉。
  找到下面的这段文本:
  <Directory />
Options FollowSymLinks
AllowOverride all
Order deny,allow
Deny from all
</Directory>
  加上“+ExecCGI”,即:
  <directory />
Options FollowSymLinks +ExecCGI
AllowOverride all
Order deny,allow
Deny from all
</Directory>
  一般来说,Perl CGI脚本就是以cgi为拓展名的,不过你也可以设置成pl为拓展名。修改方法是这样的,查找下面的这行:
  AddHandler cgi-script .cgi
  在末尾加上“.pl”,即:
  AddHandler cgi-script .cgi .pl
  
4. 重新启动Apache。
  补充问题:
  问题:The server encountered an internal error ormisconfiguration and was unable to completeyour request.
  查看$HOME/logs/error.log可以看到下面的错误:
  The system cannot find the file specified.  : couldn't create child process: 720002: printenv.pl
The system cannot find the file specified.  : couldn't spawn child process: C:/setup/Apache2.2/cgi-bin/printenv.pl
网上搜索了很多关于此问题的答案,无果。最终解决方法:
  还是看httpd的官方文档,终于解决。可能的问题为:
  #1. perl文件的文件头路径没有写正确,如#! c:/setup/perl/bin/perl.exe
  #2. 新的httpd2.2(2.0可能也这样),需要在最前面增加下面一行(下面下划线)。
  #! c:/setup/perl/bin/perl.exe
print "Content-type: text/html\n\n";
  ...your_content_below...
  为这个问题折腾了整整一天半。这一行的作用主要是告诉浏览器返回的类型,这涉及到标准CGI输出,还要明白Server和CGI和客户端的关系、通信、作用。
  --有些详细的东西,尤其是版本不一致的情况下,一定要看官方的文档,否则很容易走弯路。
页: [1]
查看完整版本: Perl_Apache_CGI_安装_windows_win7_vista