简体   繁体   English

Perl cgi脚本作为纯文本运行

[英]Perl cgi scripts ran as plain text

Before we begin, I want to say that I have read this: Perl Apache : Perl script displayed as plain text 在开始之前,我想说的是我已经读过这篇文章: Perl Apache:以纯文本形式显示的Perl脚本

I've read it, tried the things, didn't work out (Sadly) 我读过,尝试了一下,但没有解决(可悲)

I am on Ubuntu 我在Ubuntu上

I want to run cgi scripts, they compile fine, I have the appropriate rights to the folder (atleast I don't get an error that I don't when I try to enter it through the browser)and the files run as plain text. 我想运行cgi脚本,它们可以很好地编译,我对该文件夹具有适当的权限(至少当我尝试通过浏览器输入它时,没有出现我没有的错误),并且文件以纯文本格式运行。

First the file which I am trying to run: 首先,我要运行的文件:

 #!/usr/bin/perl

 use CGI qw/:standard/;
 print header,
 h1('CGI.pm is simple.'),
 end_html; 

And I get as output the source code. 我得到了源代码的输出。

The path to the folder is /var/www/a2/ 文件夹的路径是/var/www/a2/

and the configuration in the apache .config file is: apache .config文件中的配置为:

ScriptAlias /a2/ /var/www/a2/
<Directory "/var/www/a2">
AddHandler cgi-script .cgi .pl
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>

The file compiles fine and prints the html in the terminal. 该文件可以正常编译并在终端中打印html。

My only guess is that I have not given proper rights to the file. 我唯一的猜测是我没有授予该文件适当的权利。

EDIT: I checked the error log. 编辑:我检查了错误日志。 It doesn't give an error for this. 它不会为此提供任何错误。

EDIT: After a very long discussion with Mark Setchell the error was discovered. 编辑:与马克·谢彻尔(Mark Setchell)进行了很长时间的讨论后,发现了错误。 I had posted this in the wrong .config file and I had been using the wrong (unconfigured folder) all along. 我将其发布在错误的.c​​onfig文件中,并且一直使用错误的(未配置的文件夹)。

Here are some things to try: 这里有一些尝试:

  1. Ensure your script is named with the extension ".pl" 确保您的脚本以扩展名“ .pl”命名

  2. Ensure your script is executable. 确保脚本是可执行的。 Do this by typing: 通过键入以下内容:

    chmod +x yourscript.pl chmod + x yourscript.pl

  3. As Mark says, ensure you have the shebang as the very first line of your script: 如Mark所说,确保将shebang作为脚本的第一行:

    #!/usr/bin/perl #!的/ usr / bin中/ perl的

  4. Remove the "1;" 删除“ 1;” at the end, you only need that for packages/modules. 最后,您只需要软件包/模块。

I don't see a 我没看到

#!/usr/bin/perl

at the top of your script. 在脚本的顶部。 Without it, the CGI handler won't know how to execute it. 没有它,CGI处理程序将不知道如何执行它。

Make sure apache cgi mode is enable 确保启用了apache cgi模式

sudo a2enmod cgi   //will enable the cgi mode
sudo service apache2 restart

Make sure that the file permission to the .cgi file is okay 确保对.cgi文件的文件许可权正确

sudo chmod 755 yourFile.cgi

Try executing it through terminal 尝试通过终端执行

perl /Path_To_The_File/fileName.cgi

Ensure that your fileName.cgi contains bellow code at top of the file 确保您的fileName.cgi在文件顶部包含以下代码

#!/usr/bin/perl -w

print "Content-type: text/html\n\n";

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

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