Windows下配置apache CGI

作者:Kinglong    发表时间:2022-09-28 14:14   

关键词:  

https://blog.csdn.net/zhuanshu666/article/details/74936940

1.1  配置apache

按照以上网址配置apache。

其中cgi执行目录配置成D:/var/www/cgi-bin/

 ScriptAlias /cgi-bin/ "D:/var/www/cgi-bin/"

 <Directory "D:/var/www/cgi-bin/">

    AllowOverride All

    Options +ExecCGI

    Order allow,deny

    Allow from all

 </Directory>

1.2  权限报错处理

You don‘t have permission to access this resource.

<Directory />

    AllowOverride none

    Require all denied

</Directory>

改成

<Directory />

    AllowOverride none

    Require all granted

</Directory>

 

测试:编写hello.py

执行hello.py 成功

1.3  执行test.cgi报错,Can't locate CGI.pm

Can't locate CGI.pm in @INC (you may need to install the CGI module)  (@INC contains: /usr/local/lib/perl5/site_perl/5.32/x86_64-cygwin-threads /usr/local/share/perl5/site_perl/5.32 /usr/lib/perl5/vendor_perl/5.32/x86_64-cygwin-threads /usr/share/perl5/vendor_perl/5.32 /usr/lib/perl5/5.32/x86_64-cygwin-threads /usr/share/perl5/5.32) at D:/var/www/cgi-bin/test.cgi line 3.: D:/var/www/cgi-bin/test.cgi

当前解释器Perl配置为 #!C:/cygwin64/bin/perl.exe

考虑可能是Perl程序问题,重装Perl

重装perl到C:\Perl下(下载地址:http://pan.baidu.com/s/1i3GLKAp),将C:\Perl\bin添加到环境变量Path中,将test.cgi的解释器perl路径配置为新的安装地址:C:\Perl\bin,即#!C:\Perl\bin\perl.exe

test.cgi代码如下:

#!C:\Perl\bin\perl.exe

use warnings;

use CGI qw(:standard);

#! must use 'my' to define a variable

print header;

my $now_string = localtime();

print "<b>Hello, CGI using Perl!</b><br/>It's $now_string NOW!<br />";

执行test.cgi成功

1.4  Apache全目录执行cgi

处理Options ExecCGI is off

AH02809: Options ExecCGI is off in this directory: D:/Software/Apache24/htdocs/annotationTools/perl/write_logfile.cgi

 

在<Directory "${SRVROOT}/htdocs">节点下

将 Options Indexes FollowSymLinks

 

改为  Options Indexes FollowSymLinks ExecCGI

 

测试:将test.cgi拷贝到D:\Software\Apache24\htdocs和D:\Software\Apache24\htdocs\annotationTools\perl目录下,访问都成功。

解决。