【问题标题】:Perl script displayed as plain text in linux mint?Perl脚本在linux mint中显示为纯文本?
【发布时间】:2013-05-31 02:04:33
【问题描述】:

我确实安装了 libapache2-mod-perl2 以通过 apache 将 perl 文件作为 CGI 运行
每次我尝试浏览 perl 文件浏览器时,都会将其显示为纯文本。

###Start###
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello there";
###End###

这是虚拟主机文件

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/test
    ServerName  perl.dev
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/test>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /var/www/test/cgi-bin
    <Directory "/var/www/test/cgi-bin">
        AddHandler cgi-script .cgi .pl
        Options FollowSymLinks +ExecCGI
        AllowOverride none
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

当我尝试使用终端运行脚本时,它工作正常,但通过浏览器它永远不会显示正确的输出
谢谢

【问题讨论】:

  • 您实际上是通过您的网络服务器(通过 HTTP)访问它,还是尝试从文件系统访问它(使用 file:// URL)?
  • 我试图通过 HTTP 而不是从文件系统访问
  • 您的测试脚本位于哪个目录中?你是怎么命名的?
  • /var/www/test/cgi-bin
  • ###Start######End### 是您文件的一部分吗? #!/usr/bin/perl必须在第一行。

标签: perl apache cgi


【解决方案1】:

您提到“libapache2-mod-perl2”,所以您使用的是 mod_perl。

对于 mod_perl,你必须使用 SetHandler perl-script。

我在常规 cgi 和 mod-perl 之间有所区别。这就是我在 apache2 中配置 mod-perl 的方式:

ScriptAlias /perl-bin/ /usr/lib/perl-bin/
<Directory "/usr/lib/perl-bin">
       AllowOverride None
       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch

       SetHandler perl-script
       PerlResponseHandler ModPerl::Registry
       PerlOptions +ParseHeaders
       #Order allow,deny
       #Allow from all
       Require ip 127.0.0.1 192.168.0.0/16
</Directory>

【讨论】:

    猜你喜欢
    • 2013-01-25
    • 2016-03-17
    • 2014-09-18
    • 1970-01-01
    • 2018-10-15
    • 1970-01-01
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多