如何配置Apache 2以运行Perl CGI脚本? [英] How do I configure Apache 2 to run Perl CGI scripts?
问题描述
我想配置在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上正确设置Apache2 for Perl的人们. (特定于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:
- 浏览器尝试下载.pl文件而不是执行并给出结果.
- 禁止.
- 内部服务器错误.
如果一个人合理地按照以下步骤进行操作,他/她可以克服上面提到的错误.
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
步骤1:安装apache2
步骤2:安装mod_perl
步骤3:配置apache2
Step 1: Install apache2
Step 2: Install mod_perl
Step 3: Configure 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>
步骤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-you-want-your..pl-.. 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屋!