繁体   English   中英

为什么此Perl CGI脚本出现“权限被拒绝”错误?

[英]Why am I getting a “permission denied” error with this Perl CGI script?

我正在尝试制作一个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还是很陌生,我不太理解为什么会出现此错误。

由于此语句,您将收到“权限被拒绝”错误:

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

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

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

此外,请注意,如果您使用Path :: ClassPath :: Tiny,则不需要或不希望自动死亡:它们都在错误时崩溃。

您可以尝试使用以下简单脚本来查看是否一切正常:

#!/path/to/perl -T

use strict;
use warnings;
use CGI;

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

最后,看来您将覆盖每个访问者的输出文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM