如何配置 Apache 2 以运行 Perl CGI 脚本? [英] How do I configure Apache 2 to run Perl CGI scripts?

查看:33
本文介绍了如何配置 Apache 2 以运行 Perl CGI 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to configure Apache 2 running on Kubuntu to execute Perl CGI scripts. I've tried some steps that I came across by googling, but nothing seems to work.

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

What is the right way of achieving this?

推荐答案

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

This post is intended to rescue the people who are suffering from *not being able to properly setup Apache2 for Perl on Ubuntu. (The system configurations specific to your Linux machine will be mentioned within square brackets, like [this]).

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

Possible outcome of an improperly setup Apache 2:

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

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

If one follows the steps described below with a reasonable intelligence, he/she can get through the errors mentioned above.

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

Before starting the steps. Go to /etc/hosts file and add IP address / domain-name` for example:

127.0.0.1 www.BECK.com

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

Step 1: Install apache2 Step 2: Install mod_perl Step 3: Configure apache2

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

open sites-available/default and add the following,

<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>

第 4 步:

将以下行添加到您的 /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>

第 5 步:

非常重要,或者至少我是这么认为的,只有在完成这一步之后,我才能开始工作.

Step 5:

Very important, or at least I guess so, only after doing this step, I got it to work.

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

非常重要,或者至少我是这么认为的,只有在完成这一步之后,我才能开始工作.

Step 6

Very important, or at least I guess so, only after doing this step, I got it to work.

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

Add the following to you /etc/apache2/sites-enabled/000-default file

<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浏览器栏,你去,你明白了.

Give permissions to the .pl file using chmod and then, type the webaddress/cgi-bin/test.pl in the address bar of the browser, there you go, you got it.

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

(Now, many of the things would have been redundant in this post. Kindly ignore it.)

这篇关于如何配置 Apache 2 以运行 Perl CGI 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆