0

i did install libapache2-mod-perl2 to run perl files as CGI through apache
each time i tried to navigate the perl file browser display it as a plain text .

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

and this the Virtual Host File

<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>

when i tried to run the script using the terminal it just work fine but through browser it never show the right output
Thank you

4

1 回答 1

0

您提到“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>
于 2018-09-09T22:54:59.307 回答