linux - 如何配置 Apache 2 以运行 Perl CGI 脚本?

标签 linux perl apache cgi

我想配置在 Kubuntu 上运行的 Apache 2 来执行 Perl CGI 脚本。我尝试了一些通过谷歌搜索发现的步骤,但似乎没有任何效果。

实现这一目标的正确方法是什么?

最佳答案

这篇文章旨在拯救那些遭受*无法在 Ubuntu 上为 Perl 正确设置 Apache2 的人。 (特定于您的 Linux 机器的系统配置将在方括号中提及,例如 [this])。

不正确设置 Apache 2 的可能结果:

  1. 浏览器尝试下载 .pl 文件,而不是执行并给出结果。
  2. 禁止。
  3. 内部服务器错误。

如果一个人以合理的智慧遵循以下描述的步骤,他/她可以克服上述错误。

在开始这些步骤之前。转到 /etc/hosts 文件并添加 IP 地址/域名` 例如:

127.0.0.1 www.BECK.com

第 1 步:安装 apache2 第 2 步:安装 mod_perl 第三步:配置apache2

打开 sites-available/default 并添加以下内容,

<Files ~ "\.(pl|cgi)$">
    SetHandler perl-script
    PerlResponseHandler ModPerl::PerlRun
    Options +ExecCGI
    PerlSendHeader On
</Files>

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory [path-to-store-your-website-files-like-.html-(perl-scripts-should-be-stored-in-cgi-bin] >
####(The Perl/CGI scripts can be stored out of the cgi-bin directory, but that's a story for another day. Let's concentrate on washing out the issue at hand)
####
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ [path-where-you-want-your-.pl-and-.cgi-files]

<Directory [path-where-you-want-your-.pl-and-.cgi-files]>
    AllowOverride None
    Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
    AddHandler cgi-script .pl
    Order allow,deny
    allow from all
</Directory>
<Files ~ "\.(pl|cgi)$">
    SetHandler perl-script
    PerlResponseHandler ModPerl::PerlRun
    Options +ExecCGI
    PerlSendHeader On
</Files>

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>
<Directory [path-to-store-your-website-files-like-.html-(perl-scripts-should-be-stored-in-cgi-bin] >
####(The Perl/CGI scripts can be stored out of the cgi-bin directory, but that's a story for another day. Let's concentrate on washing out the issue at hand)
####
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ [path-where-you-want-your-.pl-and-.cgi-files]

<Directory [path-where-you-want-your-.pl-and-.cgi-files]>
    AllowOverride None
    Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
    AddHandler cgi-script .pl
    Order allow,deny
    allow from all
</Directory>

第四步:

将以下行添加到您的 /etc/apache2/apache2.conf 文件中。

AddHandler cgi-script .cgi .pl
<Files ~ "\.pl$">
Options +ExecCGI
</Files>
<Files ~ "\.cgi$">
Options +ExecCGI
</Files>

<IfModule mod_perl.c>
<IfModule mod_alias.c>
Alias /perl/ /home/sly/host/perl/
</IfModule>
<Location /perl>
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
</Location>
</IfModule>

<Files ~ "\.pl$">
Options +ExecCGI
</Files>

第五步:

非常重要,或者至少我猜是这样,只有在做了这一步之后,我才开始工作。

AddHandler cgi-script .cgi .pl

<Files ~ "\.pl$">
Options +ExecCGI
</Files>
<Files ~ "\.cgi$">
Options +ExecCGI
</Files>

<IfModule mod_perl.c>
<IfModule mod_alias.c>
Alias /perl/ /home/sly/host/perl/
</IfModule>
<Location /perl>
SetHandler perl-script
PerlHandler Apache::Registry
Options +ExecCGI
</Location>
</IfModule>

<Files ~ "\.pl$">
Options +ExecCGI
</Files>

第 6 步

非常重要,或者至少我猜是这样,只有在做了这一步之后,我才开始工作。

将以下内容添加到您的 /etc/apache2/sites-enabled/000-default 文件中

<Files ~ "\.(pl|cgi)$">
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options +ExecCGI
PerlSendHeader On
</Files>

第 7 步:

现在将您的 Perl 脚本作为 test.pl 添加到您之前在第 3 步中提到的位置作为 [path-where-you-want-your-.pl-and-.cgi-files]。

使用 chmod 授予 .pl 文件的权限,然后在地址中键入 webaddress/cgi-bin/test.pl浏览器栏,你去,你明白了。

(现在,这篇文章中的许多内容都是多余的。请忽略它。)

关于linux - 如何配置 Apache 2 以运行 Perl CGI 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/560749/

相关文章:

linux - 有没有办法从已经运行的程序中获取输出?

perl - XML 文件的并行处理

Apache ProxyPass 删除 Authorization header

linux -/dev/ttyACM0 : permission denied on openSUSE

linux - 使用 RDTSC 获取 cpu 周期 - 为什么 RDTSC 的值总是增加?

perl - 用于查找所有名称相似的文件的脚本(仅大小写不同?)

apache - 使用服务器端包含和 mod_deflate 压缩时发生冲突

php - 使用 mod_rewrite 将路径转换为查询字符串变量

java - ec2实例中的服务器返回https流量的最简单方法是什么?

perl - WWW::Mechanize::Firefox xpath 上的先前结果