如何在本地主机中运行 perl 脚本?

发布于 2024-12-27 18:50:44 字数 268 浏览 2 评论 0原文

我已经安装了 Apache。我在本地主机中使用 PHP 编写脚本。需要知道如何运行perl脚本。 我已经安装了 sudo aptitude install libapache2-mod-perl2 我在 /var/www/cgi-bin 中创建了一个名为 cgi-bin 的目录 在这个文件夹中我保存了我的 Perl 脚本 perl_1.pl 给出了目录权限。 我还需要做什么才能运行脚本??? 我只需输入 http://localhost/cgi-bin/ 我收到错误 403 您无权访问此服务器上的/cgi-bin/。

I had already installed Apache. I am using PHP for my scripting in localhost. Need to know how to run the perl script.
I have installed sudo aptitude install libapache2-mod-perl2
I have created a directory name cgi-bin in my /var/www/cgi-bin
there inside this folder i have kept my perl script perl_1.pl
The directory permissions are given.
What more i have to do to run the script????
i just type http://localhost/cgi-bin/
and i got error 403
You don't have permission to access /cgi-bin/ on this server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你是暖光i 2025-01-03 18:50:44

您无法读取 cgi-bin 内容。您必须直接引用其中的脚本之一,在本例中: http://localhost/cgi-bin /perl_1.pl

除此之外,请确保您的 cgi-bin/ 目录实际上在 httpd.conf 中被如此对待。

哦,万一您之后偶然发现 500:请确保您的 Perl 脚本打印有效的 HTTP 标头。这可以通过以下方式轻松实现:

use CGI qw(:standard);
print header();

正如 Pwex 指出的那样:确保您的脚本设置了可执行位。

chmod 755 perl_1.pl

...应该在大多数情况下工作

此外,为了将来的参考,值得一提的是 mod_perl,因为在掌握了 cgi + perl + apache 的基础知识之后,它是自然的下一步。详细讨论它超出了这个答案的范围,但我想我应该提到它,以便当你掌握了基础知识并看到 cgi 的局限性时,你知道下一步该去哪里。

you can't read the cgi-bin contents. You must refer directly to one of the scripts in it, in this case: http://localhost/cgi-bin/perl_1.pl

Outside of that, ensure that your cgi-bin/ directory is actually treated as such in httpd.conf.

Oh, and in case you stumble on 500 afterwards: make sure that your perl script prints a valid HTTP header. This can easily be achieved by:

use CGI qw(:standard);
print header();

And as Pwex pointed out: make sure your script has the executable bit set.

chmod 755 perl_1.pl

...should work in most cases

Additionally, for future reference it is worth mentioning mod_perl, as it is a natural next step after getting the basics of cgi + perl + apache down. Going into detail about it would be beyond the scope of this answer, but I thought I'd mention it so that you know where to go next when you've got the basics nailed down as well as seen the limitations of cgi.

套路撩心 2025-01-03 18:50:44

你的 Apache 是如何配置的?
您是否确定告诉 Apache 在 cgi-bin 目录中执行 CGI 脚本?

像这样的东西:

ScriptAlias /cgi-bin/ "/var/www/website/cgi-bin/"
<Directory "/var/www/website/cgi-bin/">
                Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

                ...
</Directory>

How's your Apache configured ?
Did you make sure you're telling the Apache to execute CGI script in the cgi-bin directory ?

Something like:

ScriptAlias /cgi-bin/ "/var/www/website/cgi-bin/"
<Directory "/var/www/website/cgi-bin/">
                Options ExecCGI -MultiViews +SymLinksIfOwnerMatch

                ...
</Directory>
雨巷深深 2025-01-03 18:50:44

如果您没有依赖 apache 或者可以在不同的端口上运行这些脚本,那么您可以使用 Plack/PSGI 工具链,该工具链具有将旧 CGI 脚本作为 PSGI 应用程序运行的解决方案。请参阅在 Plack 上运行 CGI 脚本 有几种方法可以做到这一点。

If you are not tied to apache or can run these scripts on different port then you can use Plack/PSGI toolchain that have solutions to run old CGI scripts as PSGI applications. See Running CGI scripts on Plack for several ways to do it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文