【问题标题】:Why am I getting a "permission denied" error with this Perl CGI script?为什么我收到此 Perl CGI 脚本的“权限被拒绝”错误?
【发布时间】:2016-11-03 04:33:54
【问题描述】:

我正在尝试制作一个 Perl 脚本,该脚本在远程主机访问某个网站时获取远程主机的 IP 地址。但是我似乎无法克服这个 apache 错误:

Permission denied at path_to_perl_script line 19

我在 Ubuntu 服务器上运行一个网站,并且我已经正确配置了 Apache2 和 CGI​​。

这是login.pl 脚本:

#!/usr/bin/perl -T
use CGI;
use DBI;
use strict;
use warnings;
use Path::Class;
use autodie;    

# read the CGI params
my $cgi = CGI->new;
my $username = $cgi->param("username");
my $password = $cgi->param("password");

my $port = $cgi->remote_host();

my $dir = dir("var/www/html");
my $file = dir->file("testingPerl.txt");
my $file_handle = $file->openw();
$file_handle->print($port);

我对 Perl 还很陌生,我不太明白为什么会出现这个错误。

【问题讨论】:

  • 这是我制作的唯一 perl 脚本,所以.....@zdim
  • 我了解@zdim,但上面的脚本是“login.pl”,抱歉我已经更新了问题,说这是那个文件。否则我不知道错误可能来自哪里......
  • 好的,更好吗? @zdim,我应该添加任何内容以使其更清晰吗?
  • 我建议我们整理并删除这些不再有用的 cmets(可能是前两个和后两个?)。当您将鼠标悬停在您的评论上时,它会显示一个小十字,如果您点击它,评论就会被删除(首先会出现一个确认对话框)。
  • 非常感谢您的帮助!是的,首先,我会尝试写入文件,但是,每次我尝试使用问题中的更新代码时,我都会在 apache error.log 中收到权限被拒绝错误。我一直在阅读有关此问题的一些主题,显然使用“chmod”更改权限并不能解决此问题。 @zdim 有什么想法吗?

标签: apache perl ubuntu scripting cgi


【解决方案1】:

由于以下语句,您会收到“权限被拒绝”错误:

my $dir = dir("var/www/html");

路径var/www/html 是相对于脚本的当前工作目录的,它不太可能存在。你可能想要的是/var/www/html

但是,您的脚本以运行 Web 服务器的用户 ID 的权限运行。在正常配置中,通常不允许该用户写入/var/www/html。因此,修复它可能无法解决您的问题。

此外,请注意,如果您使用 Path::ClassPath::Tiny,则不需要或不想要 autodie:它们都会因错误而发牢骚。

你可以试试这个简单的脚本看看是否一切正常:

#!/path/to/perl -T

use strict;
use warnings;
use CGI;

my $cgi = CGI->new;
print $cgi->header('text/plain'), $cgi->remote_host, "\n";

最后,您似乎要覆盖每个访问者的输出文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 2015-08-06
    • 2019-11-19
    • 1970-01-01
    相关资源
    最近更新 更多