Perl的Apache:Perl脚本显示为纯文本 [英] Perl Apache : Perl script displayed as plain text
问题描述
虽然与阿帕奇
和的Perl CGI脚本
,不知道为什么配置指数的CGI
/ index.pl
显示为纯文本,而不是执行它们。
当我把的http://本地主机
在浏览器中会显示以下code,而不是执行它。
列表项
#!C:/Dwimperl/perl/bin/perl.exe -w 打印内容类型:text / html的\\ n \\ n;
打印<< HTML;
< HTML和GT;
< HEAD>
<标题>一种perl的网页< /标题>
< /头>
<身体GT;
< H3>一种世界你好形式的perl< / H3 GT&;
< /身体GT; HTML
出口;
这是我所编辑的大部分时间的httpd.conf
部分文件(阅读各种在线参考后,教程)
#这应改为你设置的DocumentRoot。
<目录D:\\网络服务器>听80
服务器名本地主机:80
的LoadModule cgi_module模块/ mod_cgi.so#首先,我们配置的默认是一个非常严格的一套
# 特征。
<目录/>
有FollowSymLinks + ExecCGI
设置AllowOverride无
< /目录>的DirectoryIndex index.html的index.html变量index.cgi文件index.plAccessFileName的.htaccess#要使用CGI脚本ScriptAliased指令之外:
#(你还需要为ExecCGI添加到选项指令。)
#
#AddHandler CGI脚本的CGI特等ScriptAlias指令/的cgi-bin /C:/阿帕奇/的Apache2 / cgi-bin目录/
在浏览器打印脚本code,这意味着它无法找到运行脚本程序。下面两行应该解决这个你的第一个步骤。 AddHandler的将与的CGI
和特等
被视为CGI脚本结束确认文件。和 + ExecCGI
选项将允许执行脚本。另外,还要确保你的脚本指向正确的perl程序的位置。
AddHandler的CGI脚本的CGI特等
有FollowSymLinks + ExecCGI
块引用>也有一些错误/错误配置点你的httpd.conf
- 别名行应指向的cgi-bin 目录,其中的CGI脚本是present。
的ScriptAlias / cgi-bin目录/D:\\网络服务器\\的cgi-bin
块引用>
- 对于相同的cgi-bin目录下面的配置应该是
的httpd.conf
。你应该更换你的<目录。D:\\网络服务器>在低于
部分<目录D:\\网络服务器\\ cgi-bin目录/>
AddHandler的CGI脚本的CGI特等
有FollowSymLinks + ExecCGI
设置AllowOverride无
< /目录>
块引用>
- 尝试从命令行运行CGI脚本如下图所示。它应打印或在命令行先运行。
的Perl test.cgi
块引用>
- 确保您已阅读,编写递归权限
的cgi-bin
目录和CGI脚本。 ,你也可以创建目录或写权限的文件。如果在其他地方没有创建一个的cgi-bin
目录,你可以有写权限,并提供更确切地说,它在别名
和目录
中的属性的httpd.conf
代替。- 检查Apache的错误日志中确切的错误信息在每次遇到的apache的conf问题的时间。它会给你善于洞察问题。
此外此链接应该帮助你。
(附加注释,而不是原来的回答者的:你可能还需要启用
CGI
模块对于我来说,最后一步使CGI在一个新的工作,安装Apache 2的是须藤a2enmod CGI
。我这样做之前,该网站只是给我看剧本的内容。)
须藤a2enmod CGI
块引用>While configuring with
apache
andperl cgi scripts
, don't know whyindex.cgi
/index.pl
are displayed as plain text instead of executing them. When I puthttp://localhost
in browser it displays below code, instead of executing it.List item #!C:/Dwimperl/perl/bin/perl.exe -w print "Content-type: text/html\n\n"; print <<HTML; <html> <head> <title>A perl web page</title> </head> <body> <h3>A hello world form perl</h3> </body> HTML exit;
This are parts of
httpd.conf
file which I have edited most of the times (after reading various online reference, tutorials)# This should be changed to whatever you set DocumentRoot to. <Directory "D:\webserver"> Listen 80 ServerName localhost:80 LoadModule cgi_module modules/mod_cgi.so # First, we configure the "default" to be a very restrictive set of # features. <Directory /> Options FollowSymLinks +ExecCGI AllowOverride None </Directory> DirectoryIndex index.html index.html.var index.cgi index.pl AccessFileName .htaccess # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #AddHandler cgi-script .cgi .pl ScriptAlias /cgi-bin/ "C:/Apache/Apache2/cgi-bin/"
解决方案When browser is printing code of script that means it's unable to find the application to run the script. Below two lines should be your first steps to solve this. AddHandler will make sure files ending with
.cgi
and.pl
to be treated as cgi scripts. And+ExecCGI
option will allow to execute the script. Also make sure your script is pointing to correct perl binary location.AddHandler cgi-script .cgi .pl Options FollowSymLinks +ExecCGI
Also There are some mistakes/misconfiguration points in your httpd.conf
- Alias line should point to cgi-bin directory where your cgi scripts are present.
ScriptAlias /cgi-bin/ "D:\webserver\cgi-bin"
- For same cgi-bin directory following configuration should be in
httpd.conf
. You should replace your<Directory "D:\webserver">
part with below.<Directory "D:\webserver\cgi-bin" /> AddHandler cgi-script .cgi .pl Options FollowSymLinks +ExecCGI AllowOverride None </Directory>
- Try running your cgi script from command line like below. It should print or run from command line first.
perl test.cgi
- Make sure you have read-write recursive permissions to
cgi-bin
directory and your cgi script. And also you can create directory or file with write permissions. If not create acgi-bin
directory at some other place where you can have write permissions and provide rather its path inalias
anddirectory
attributes inhttpd.conf
instead.- Check apache error log for exact error message every time you run into apache conf issues. It will give you good insight into the problem.
Also this link should help you.
(Extra comment, not by the original answerer: You may also need to enable the
cgi
module. For me, the final step to getting cgi to work on a fresh install of Apache 2 wassudo a2enmod cgi
. Before I did that, the website simply showed me the contents of the script.)
sudo a2enmod cgi
这篇关于Perl的Apache:Perl脚本显示为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!