-3 apache xampp permissions perl cgi
我想用PERL做一个简单的测试.我编写了input.html并将其放在hgi文件夹中,并将其放在cgi-bin中的output.cgi中.两者都在XAMPP文件夹中,使用mac.这也是使用apache.
HTML文件
<!doctype html>
<html lang="en">
<body>
<form action="/cgi-bin/output.cgi" method="post">
Enter Fahrenheit: <input type="text" name="fahrenheit" /><br />
Enter Distance in Miles: <input type="text" name="distance" /><br />
<input type="submit" value="Convert!" />
</form>
Run Code Online (Sandbox Code Playgroud)
这是用户按"转换"时应显示的CGI文件
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
#### read form data
my $fahrenheit = param('fahrenheit');
my $distance = param('distance');
#### do the math
my $celcius = ($fahrenheit * 18.8) + 32;
my $kilometers = $distance * 1.60934;
#### display results
print "<h2>Assignment 3</h2>";
print "Conversion: <br />";
printf "Celcius: \$%.2f <br />", $celcius;
printf "Kilometers: \$%.2f <br />", $kilometers;
Run Code Online (Sandbox Code Playgroud)
这是Apache的错误日志
Marker - Oct 15, 2016, 5:56:38 PM
[Sat Oct 15 17:56:41.765457 2016] [cgi:error] [pid 3086] [client ::1:50144] AH01215: (13)Permission denied: exec of '/Applications/XAMPP/xamppfiles/cgi-bin/output.cgi' failed: /Applications/XAMPP/xamppfiles/cgi-bin/output.cgi, referer: http://localhost/input.html
[Sat Oct 15 17:56:41.765785 2016] [cgi:error] [pid 3086] [client ::1:50144] End of script output before headers: output.cgi, referer: http://localhost/input.html
Run Code Online (Sandbox Code Playgroud)
这就是localhost中应该显示output.cgi的页面
Server error!
The server encountered an internal error and was unable to complete your request.
Error message:
End of script output before headers: output.cgi
If you think this is a server error, please contact the webmaster.
Error 500
localhost
Apache/2.4.23 (Unix) OpenSSL/1.0.2h PHP/5.6.24 mod_perl/2.0.8-dev Perl/v5.16.3
Run Code Online (Sandbox Code Playgroud)
正如错误日志所述,Apache没有执行CGI文件的权限
为每个人使用添加执行权限chmod a+x cgi-bin/output.cgi,它应该适合您
顺便说一句,温度的转换应该是
$celcius = ( $fahrenheit - 32 ) / 1.8
Run Code Online (Sandbox Code Playgroud)
你的问题就像在问:"我把钥匙放在我的车上,而我还没在莱斯特.我做错了什么?"
您似乎无法output.cgi从命令行指定文件的路径.这不是问题:这是一个缺陷.您必须了解有关正在使用的shell的更多信息
如果你真的不能这样做,那么你在方式在你的头顶,所以你必须停止,并通过一些教程工作
查看错误日志,output.cgi位于
/Applications/XAMPP/xamppfiles/cgi-bin/output.cgi
Run Code Online (Sandbox Code Playgroud)
所以你可以
chmod a+x /Applications/XAMPP/xamppfiles/cgi-bin/output.cgi
Run Code Online (Sandbox Code Playgroud)
要么
cd /Applications/XAMPP/xamppfiles/cgi-bin
Run Code Online (Sandbox Code Playgroud)
其次是
chmod a+x output.cgi
Run Code Online (Sandbox Code Playgroud)